【zoj】【Attack on Titans】
来源:互联网 发布:淘宝互刷平台 编辑:程序博客网 时间:2024/06/08 02:24
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.
#include <iostream>#include <cstring>#include <cmath>#include <queue>#include <stack>#include <list>#include <map>#include <set>#include <string>#include <cstdlib>#include <cstdio>#include <algorithm>using namespace std;typedef long long LL;LL n,m,k,u,v;LL ans1;LL ans2;const LL maxn = 1000100;const LL mod = 1000000007;LL dp[maxn][3];// dp[][0] ---> G// dp[][1] ---> R// dp[][2] ---> PLL fun(LL u,LL v) // G <= u R <= v{/*memset(dp,0,sizeof(dp));dp[0][0] = 0;dp[0][1] = 0;dp[0][2] = 1;for(LL i=1;i<=n;i++){//Case1 : dp[][0] = Gif(i <= u) dp[i][0] = (dp[i-1][0] + dp[i-1][1] + dp[i-1][2]) % mod;else dp[i][0] = (dp[i-1][0] + dp[i-1][1] + dp[i-1][2] - dp[i-u-1][1] -dp[i-u-1][2]) % mod;//Case2 : dp[][1] = Rif(i <= v) dp[i][1] = (dp[i-1][0] + dp[i-1][1] + dp[i-1][2]) % mod;else dp[i][1] = (dp[i-1][0] + dp[i-1][1] + dp[i-1][2] - dp[i-v-1][0] - dp[i-v-1][2]) % mod;dp[i][2] = (dp[i-1][0] + dp[i-1][1] + dp[i-1][2]) % mod;}return (dp[n][0] + dp[n][1] + dp[n][2]) % mod;*/ dp[0][0]=0; //初始状态 dp[0][1]=0; dp[0][2]=1; for(int i=1;i<=n;i++) { LL sum=(dp[i-1][0]+dp[i-1][1]+dp[i-1][2])%mod; dp[i][2]=sum; if(i<=u) dp[i][0]=sum; else dp[i][0]=(sum-dp[i-u-1][1]-dp[i-u-1][2])%mod; if(i<=v) dp[i][1]=sum; else dp[i][1]=(sum-dp[i-v-1][0]-dp[i-v-1][2])%mod; //printf("u:%lld v:%lld i:%d %lld %lld %lld\n",u,v,i,dp[i][0],dp[i][1],dp[i][2]); //system("pause"); } return (dp[n][0]+dp[n][1]+dp[n][2])%mod;}int main(){//freopen("1.txt","r",stdin);while(scanf("%lld%lld%lld",&n,&m,&k) != EOF){ans1 = 0;ans2 = 0;u = n ;v = k;ans1 = fun(u,v);//cout << "----" << u << " " << v << endl;u = m-1;v = k;ans2 = fun(u,v);//cout << "----" << u << " " << v << endl;//cout << "ans 1 : " << ans1 << " ans 2: " << ans2 << endl; ans1=((ans1-ans2)%mod+mod)%mod;printf("%lld\n",ans1);}}
- 【zoj】【Attack on Titans】
- Attack on Titans ZOJ
- Attack on Titans ZOJ
- ZOJ 3747 Attack on Titans
- ZOJ 3747 Attack on Titans
- ZOJ 3747 Attack on Titans
- Attack on Titans ZOJ 3747
- 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
- hadoop Unhealthy Nodes
- 两个类相互调用的问题
- linux配置NTP Server
- lucene入门demo
- ECharts使用——封装类库的使用20150713
- 【zoj】【Attack on Titans】
- CentOS 7.0编译安装Nginx+MySQL+PHP
- 大型高并发高负载web应用系统架构-数据库架构策略
- Objective-C - 改变NSMutableArray的特定元素
- dp cf C. Mr. Kitayuta, the Treasure Hunter
- linux declare
- 1、cocos2d-x Lua安装配置
- linux下产生core文件以及不产生core文件的条件-----调试例程
- 遮罩层