zoukankan      html  css  js  c++  java
  • 2018. The Debut Album

    http://acm.timus.ru/problem.aspx?space=1&num=2018

    真心爱过,怎么能彻底忘掉

    题目大意:

    长度为n的串,由1和2组成,连续的1不能超过a个,连续的2不能超过b个

    dpa[i] 表示长度为i时以a为结尾的串的个数,dpb[i] 类似

    求dpa[i]时 需要枚举结尾a的个数就可以了 dpb[i] 类似

    #include <iostream>
    #include <stdio.h>
    #include <stdlib.h>
    #include <io.h>
    #include <string.h>
    
    using namespace std;
    
    const int N=50001;
    const int M=301;
    const unsigned int MOD=1000000007;
    unsigned int dpa[N];
    unsigned int dpb[N];
    int main()
    {
        //freopen("data.in","r",stdin);
        memset(dpa,0,sizeof(dpa));
        memset(dpb,0,sizeof(dpb));
        int n,a,b;
        cin>>n>>a>>b;
        dpa[0]=dpb[0]=1;
        for(int i=1;i<=n;++i)
        {
            for(int j=1;j<=a&&j<=i;++j)
            {
                dpa[i]=(dpa[i]+dpb[i-j])%MOD;
            }
            for(int j=1;j<=b&&j<=i;++j)
            {
                dpb[i]=(dpb[i]+dpa[i-j])%MOD;
            }
        }
        cout<<((dpa[n]+dpb[n])%MOD)<<endl;
        return 0;
    }
    

      

  • 相关阅读:
    js计算两个时间相差天数
    享元模式
    外观模式
    组合模式
    装饰者模式
    桥接模式
    适配器模式
    元素量词 ? + *
    linux安装使用7zip
    linux shell使用别名,切换当前目录
  • 原文地址:https://www.cnblogs.com/liulangye/p/4281968.html
Copyright © 2011-2022 走看看