您的位置:首页 > 其它

2018. The Debut Album

2015-02-09 17:07 330 查看
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
;
unsigned int dpb
;
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
+dpb
)%MOD)<<endl;
return 0;
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: