ZOJ 3747 Attack on Titans
来源:互联网 发布:与权志龙合照软件 编辑:程序博客网 时间:2024/05/23 13:13
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.
Author: ZOU, Xun
Source: ZOJ Monthly, January 2014
#include <iostream>#include <cstdio>#include <climits>#include <cstring>#include <cstdlib>#include <cmath>#include <vector>#include <queue>#include <algorithm>#define esp 1e-6#define inf 0x0f0f0f0f#define LL long long #define imod 1000000007 #define IG 0#define IR 1#define IP 2using namespace std;/************************************************ Desiner:hl time:2016/02/17Exe.Time:124MS Exe.Memory:5528K 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5170 题意:给n个士兵排队,每个士兵三种G、R、P可选,求至少有m个连续G士兵,最多有k个连续R士兵的排列的种数。 题解:dp递推 ************************************************/ LL dp[1000005][4];LL N,M,K;LL mydp(LL u,LL v){LL i;dp[0][2]=1;//初始化 dp[0][1]=dp[0][0]=0;for(i=1;i<=N;i++){LL sum=((dp[i-1][IG]+dp[i-1][IR]+dp[i-1][IP])%imod+imod)%imod;dp[i][IP]=sum%imod;if(i<=u) dp[i][IG]=sum%imod;if(i==u+1) dp[i][IG]=((sum-1)%imod+imod)%imod;if(i>u+1) dp[i][IG]=((sum-dp[i-u-1][IP]-dp[i-u-1][IR])%imod+imod)%imod;if(i<=v) dp[i][IR]=sum%imod;if(i==v+1) dp[i][IR]=((sum-1)%imod+imod)%imod;if(i>v+1) dp[i][IR]=((sum-dp[i-v-1][IG]-dp[i-v-1][IP])%imod+imod)%imod; //cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl;}return (dp[N][IP]+dp[N][IG]+dp[N][IR])%imod;}int main(){LL i,j,k,l,m,n,G,R,P;while(~scanf("%lld%lld%lld",&N,&M,&K)){if(N==0&&M==0&&K==0) break;LL ans = mydp(N,K);LL ans1 =mydp(M-1,K);//cout<<ans << " "<<ans1<<endl;ans = (ans - ans1 +imod)%imod;printf("%lld\n",ans);}return 0;}
- ZOJ 3747 Attack on Titans
- ZOJ 3747 Attack on Titans
- ZOJ 3747 Attack on Titans
- Attack on Titans ZOJ 3747
- 【zoj】【Attack on Titans】
- Attack on Titans ZOJ
- Attack on Titans ZOJ
- ZOJ 3747 Attack on Titans(DP)
- Attack on Titans ZOJ - 3747 DP
- zoj 3747 Attack on Titans【递推好题】
- [递推dp] zoj 3747 Attack on Titans
- ZOJ 题目3747 Attack on Titans(DP)
- xtu 1233 Coins && zoj 3747 Attack on Titans
- dp递推 zoj 3747 Attack on Titans
- zoj 3747 Attack on Titans 递推 计数dp
- [ZOJ 3747] Attack on Titans (计数DP + 连续至多 + 连续至少)
- ZOJ 3747 Attack on Titans【带限制条件的递推dp+计数技巧】
- zoj 3747 Attack on Titans 带限制条件的计数递推dp
- 使用 Elasticsearch ik分词实现同义词搜索
- 【图形处理】如何将一个平面图形按照角度往z轴扭曲?
- 分享一个apns的项目
- 在Windows下使用curl命令
- hadoop I/O笔记
- ZOJ 3747 Attack on Titans
- tf卡数据恢复,手机里tf热插拔造成手机无法识别,TF卡电脑无法读取,提示使用前需要格式化
- Javascript对象中关于setTimeout和setInterval的this介绍
- R Programming Notes
- 有关在 Windows 中进行搜索的高级提示
- CURL使用
- Ide中ButterKnife配置
- ip地址的五类
- vector的内存释放