zoukankan      html  css  js  c++  java
  • URAL 2018 The Debut Album(DP)

    2018. The Debut Album

    Time limit: 2.0 second
    Memory limit: 64 MB
    Pop-group “Pink elephant” entered on recording their debut album. In fact they have only two songs: “My love” and “I miss you”, but each of them has a large number of remixes.
    The producer of the group said that the album should consist of n remixes. On second thoughts the musicians decided that the album will be of interest only if there are no more than a remixes on “My love” in a row and no more than b remixes on “I miss you” in a row. Otherwise, there is a risk that even the most devoted fans won’t listen to the disk up to the end.
    How many different variants to record the album of interest from n remixes exist? A variant is a sequence of integers 1 and 2, where ones denote remixes on “My love” and twos denote remixes on “I miss you”. Two variants are considered different if for some i in one variant at i-th place stands one and in another variant at the same place stands two.

    Input

    The only line contains integers nab (1 ≤ ab ≤ 300; max(a,b) + 1 ≤ n ≤ 50 000).

    Output

    Output the number of different record variants modulo 109+7.

    Sample

    input output
    3 2 1
    
    4
    

    Notes

    In the example there are the following record variants: 112, 121, 211, 212.



    题目的大意是指,给出n长度的数列,其实1的连续个数不超过a,2的连续个数不超过b

    这种水dp就不三步走战略了,直接上,遍历连着的a或连着的b就好了。

    一道比较水的基础DP题目。

    #include <bits/stdc++.h>
    using namespace std;
    
    const int MOD = 1e9+7;
    int n,a, b, dp[3][50005];///dp[i][j]是指长度为j,以i结尾的序列的种数,它是由后面小于等于a/b长度均为1/2的序列的种数累加而成的
    int main()
    {
      scanf("%d%d%d",&n,&a,&b);
      dp[1][0] = dp[2][0] = 1;
      for(int i = 1; i <= n; ++ i)
      {
        for(int j = 1; j <= a&&i>=j; ++ j)
            dp[1][i] = (dp[1][i] + dp[2][i-j]) % MOD;///i-j==0意味着最后的a个都是1,也是合法的序列
        for(int j = 1; j <= b&&i>=j; ++ j)
            dp[2][i] = (dp[2][i] + dp[1][i-j]) % MOD;
      }
      printf("%d
    ",(dp[1][n] + dp[2][n]) % MOD) ;
      return 0;
    }



    当时做这道题的时候我在A其他题,所以具体代码我也就没看,完了之后发现代码简直是一坨Shit,完全不符合W神的称号啊,默默地讽刺他一波偷笑,反正估计以后他也不会在看这种水题的代码了,呃呃呃。。。其实整体思路是一样的,不过他这种分情况了,如果有10个字母,这种思路怎么敲。。ORZ。。

    #include<bits/stdc++.h>
    using namespace std;
    
    #define mod 1000000007
    int dp[2][305][2];
    int main()
    {
        memset(dp, 0, sizeof(dp));
        int n,a,b;
        dp[0][1][0] = dp[1][1][0] = 1;
        scanf("%d%d%d",&n,&a,&b);
        int kk = 1;
      //  int ml = max(a,b);
        for(int l = 2; l <= n; l++){
                
            int ml = (l-1)<a?(l-1):a;
            dp[1][1][kk] = 0;
            for(int i = 1; i <= ml; i++ ){
                dp[1][1][kk] = (dp[0][i][kk^1] + dp[1][1][kk])%mod;
            }
            
            ml = (l-1)<(b-1)?(l-1):(b-1);
            for(int i = 1; i <= ml; i++){
                if(i != 0) dp[1][i+1][kk] = 0;
                dp[1][i + 1][kk] = (dp[1][i + 1][kk] + dp[1][i][kk^1])%mod;
            }
            
            ml = (l-1)<b?(l-1):b;
            dp[0][1][kk] = 0;
            for(int i =1 ; i <= ml ;i++){
                dp[0][1][kk] =(dp[0][1][kk] + dp[1][i][kk^1])%mod;
            }
            
            
            ml = (l-1) <(a-1)?(l-1):(a-1);
            for(int i= 1; i <= ml; i++){
                if(i != 0) dp[0][i+1][kk] = 0;
                dp[0][i+1][kk] = (dp[0][i+1][kk] + dp[0][i][kk^1])%mod;
            }
            kk ^= 1;
        }
        int ans = 0;
        int mx = max(a,b);
        for(int i = 1; i <= mx; i++){
            if(i <= a) ans =(ans + dp[0][i][kk^1])%mod;
            if(i <= b) ans =(ans + dp[1][i][kk^1])%mod;
        }
        printf("%d
    ", ans);
        return 0;
    }
    








  • 相关阅读:
    Mybatis Plus整合PageHelper分页的实现示例
    关于xlrd最新版本不支持.xlsx文件的解决办法
    mysql 错误解决大法 Specified key was too long; max key length is 767 bytes
    php连接redis
    flask通过request.path获取定义view函数的文件和行号
    使用bash内置命令complete来实现参数补全
    linux下对比两个文件夹下python文件的差异
    ssh登录后自动切换到原来的目录
    ssh &2>1 和重定向顺序问题
    wsl1(win10)中安装bochs
  • 原文地址:https://www.cnblogs.com/zswbky/p/8454168.html
Copyright © 2011-2022 走看看