zoj 3747 递推dp

Attack on Titans


Time Limit: 2 Seconds      Memory Limit: 65536 KB

Over centuries ago, mankind faced a new enemy, the Titans. The difference of power between mankind and their newfound enemy was overwhelming. Soon, mankind was driven to the brink of extinction. Luckily, the surviving humans managed to build three walls: Wall Maria, Wall Rose and Wall Sina. Owing to the protection of the walls, they lived in peace for more than one hundred years.

But not for long, a colossal Titan appeared out of nowhere. Instantly, the walls were shattered, along with the illusory peace of everyday life. Wall Maria was abandoned and human activity was pushed back to Wall Rose. Then mankind began to realize, hiding behind the walls equaled to death and they should manage an attack on the Titans.

So, Captain Levi, the strongest ever human being, was ordered to set up a special operation squad of N people, numbered from 1 to N. Each number should be assigned to a soldier. There are three corps that the soldiers come from: the Garrison, the Recon Corp and the Military Police. While members of the Garrison are stationed at the walls and defend the cities, the Recon Corps put their lives on the line and fight the Titans in their own territory. And Military Police serve the King by controlling the crowds and protecting order. In order to make the team more powerful, Levi will take advantage of the differences between the corps and some conditions must be met.

The Garrisons are good at team work, so Levi wants there to be at least M Garrison members assigned with continuous numbers. On the other hand, members of the Recon Corp are all elite forces of mankind. There should be no more than K Recon Corp members assigned with continuous numbers, which is redundant. Assume there is unlimited amount of members in each corp, Levi wants to know how many ways there are to arrange the special operation squad.

Input

There are multiple test cases. For each case, there is a line containing 3 integers N (0 < N < 1000000), M (0 < M < 10000) and K (0 < K < 10000), separated by spaces.

Output

One line for each case, you should output the number of ways mod 1000000007.

Sample Input

3 2 2

Sample Output

5

Hint

Denote the Garrison, the Recon Corp and the Military Police as G, R and P. Reasonable arrangements are: GGG, GGR, GGP, RGG, PGG.

题解:https://blog.csdn.net/papapa_swust/article/details/77745984

#include <iostream>
#include <cstdio> const int N = +;
const int mod = 1e9+;
typedef long long ll;
int n,m,k; ll dp[N][]; ll _mod(ll x)
{
x %= mod;
x = (x+mod)%mod;
return x;
} ll cal(int u,int v)
{
dp[][]=,dp[][]=,dp[][]=;
for(int i=;i<=n;i++)
{
ll sum= (dp[i-][]+dp[i-][]+dp[i-][])%mod;
dp[i][] = sum;
if(i <= u)
dp[i][] = sum;
//else if(i == u+1)
//dp[i][0] = _mod(sum-1);
else
dp[i][] = _mod(sum - dp[i-u-][]-dp[i-u-][]);
if(i <= v)
dp[i][] = sum;
//else if(i == v+1)
//dp[i][1] = _mod(sum-1);
else
dp[i][] = _mod(sum - dp[i-v-][]-dp[i-v-][]);
}
return _mod(dp[n][]+dp[n][]+dp[n][]);
} int main ()
{ while (scanf("%d%d%d",&n,&m,&k)==)
{
printf("%lld\n",_mod(cal(n,k)-cal(m-,k)));
}
return ;
}
上一篇:Linux Kernel ‘/bcm/Bcmchar.c’本地信息泄露漏洞


下一篇:【matlab 图像处理2】直方图均衡化、规定化