Click to open link
2018. The debut albumtime limit:2.0 second
Memory limit:64 MB
Pop-group "Pink Elephant" entered on recording their debut album. In fact they there are only the songs: "My Love" and "I Miss You", but each of the them has a large number of remixes. The producer of the group said that the album should consist of
NRemixes. On second thoughts the musicians decided that the album would be is the interest only if there is no more than
aRemixes on ' My Love ' in a row and no more than
bRemixes on ' I Miss you ' in a row. Otherwise, there is a risk this 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
NRemixes 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 ”. Variants is considered different if for some
IIn one variant at
I-th Place stands one and in another variant on the same place stands. Inputthe only line contains integers
N,
a,
b(1≤
a,
b≤300;
Max(
a,
b) + 1≤
N≤50 000). Outputoutput the number of different record variants modulo 109+7.sample
Hintin The example there is the following record variants:112, 121, 211, 212.
problem Author:Olga Soboleva (prepared by Alex Samsonov)
problem Source:NEERC, Eastern Subregional contest
constructs a string of length n of only 1 and 2, requires that the number of consecutive 1 must not exceed a, the number of consecutive 2 can not exceed B, to find a total number of matching cases of the string.
Reference: Click to open Link
0.562210 kb#include<stdio.h> #include <string.h> #include <algorithm> #define M 1000000007#define ll long longusing namespace Std;ll dp[2][2][307];int main () {int n,a,b,now,pre; while (scanf ("%d%d%d", &n,&a,&b)!=eof) {memset (dp,0,sizeof (DP)); Dp[0][0][0]=1;dp[0][1][0]=1; for (int i=1;i<=n;i++) {now=i&1,pre= (i-1) &1; memset (dp[now],0,sizeof (Dp[now)); for (int j=1;j<=a;j++) {dp[now][0][j]+=dp[pre][0][j-1]; if (dp[now][0][j]>m) dp[now][0][j]%=m; DP[NOW][1][1]+=DP[PRE][0][J]; if (dp[now][1][1]>m) dp[now][1][1]%=m; } for (int j=1;j<=b;j++) {dp[now][1][j]+=dp[pre][1][j-1]; if (dp[now][1][j]>m) dp[now][1][j]%=m; DP[NOW][0][1]+=DP[PRE][1][J]; if (dp[now][0][1]>m) dp[now][0][1]%=m; }} ll Ans=0; for (int i=1;i<=a;i++) {ans+=dp[n&1][0][i]; if (ans>m) ans%=m; } for (int i=1;i<=b;i++) {ans+=dp[n&1][1][i]; if (ans>m) ans%=m; } printf ("%lld\n", ans); } return 0;}
Ural 2018. The debut Album scroll array dp