码迷,mamicode.com
首页 > 其他好文 > 详细

2018. The Debut Album

时间:2015-02-09 18:16:33      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:

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;
}

  

2018. The Debut Album

标签:

原文地址:http://www.cnblogs.com/liulangye/p/4281968.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!