2018. The Debut Album
Time limit: 2.0 second
Memory limit: 64 MB
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
n,
a,
b (1 ≤
a,
b ≤ 300;
max(
a,
b) + 1 ≤
n ≤ 50 000).
Output
Output the number of different record variants modulo 10
9+7.
Sample
input | output |
---|---|
3 2 1 |
4 |
Notes
In the example there are the following record variants: 112, 121, 211, 212.
Problem Author: Olga Soboleva (prepared by Alex Samsonov)
Problem Source: NEERC 2014, Eastern subregional contest
Problem Source: NEERC 2014, Eastern subregional contest
Difficulty: 102
Printable version
Submit solution
Discussion (8)
All submissions (5782) All accepted submissions (1930) Solutions rating (1293)
All submissions (5782) All accepted submissions (1930) Solutions rating (1293)
#include<bits/stdc++.h> #define ll long long using namespace std; ll mod = 1e9+7; ll a, b, dp[2][2][307]; int n; /* 问题:求满足要求的混合音符的种类数 当前状态f[i][j][k] : 表示 第i个为j{0, 1}时,连续k个后缀是j; 那么 k : 1 -> a dp[i][0][k] += dp[i - 1][0][k - 1]; dp[i][1][1] += dp[i - 1][0][k]; k : 1 -> b dp[i][1][k] += dp[i - 1][1][k - 1]; dp[i][0][1] += dp[i - 1][1][k]; 这样50000*2*300太大了,所以用滚动数组。。。 上面的状态转移方程我们可以用滚动数组2*2*300; */ ll solve() { memset(dp, 0, sizeof(dp)); dp[1][1][1] = 1; dp[1][0][1] = 1; for(int i = 2; i <= n; i++) { int 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[now][0][j] + dp[pre][0][j-1])%mod; dp[now][1][1] = (dp[now][1][1] + dp[pre][0][j])%mod; } for(int j = 1; j <= b; j++) { dp[now][1][j] = (dp[now][1][j] + dp[pre][1][j-1])%mod; dp[now][0][1] = (dp[now][0][1] + dp[pre][1][j])%mod; } } ll ans = 0; int now = n&1; for(int i = 1; i <= a; i++) ans = (ans + dp[now][0][i])%mod; for(int i = 1; i <= b; i++) ans = (ans + dp[now][1][i])%mod; return ans; } int main() { //freopen("in.txt", "r", stdin); while(~scanf("%d%lld%lld", &n, &a, &b)) { printf("%lld\n", solve()); } return 0; }