Attack on Titans ZOJ
来源:互联网 发布:如何做数据透视表 编辑:程序博客网 时间:2024/05/30 04:57
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 ofN 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 thanK 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.
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.
One line for each case, you should output the number of ways mod 1000000007.
3 2 2
5
Denote the Garrison, the Recon Corp and the Military Police as G, R and P. Reasonable arrangements are: GGG, GGR, GGP, RGG, PGG.
题意 一共有n个团队(grp),至少m个g士兵连续,至多k个r连续,一共有多少种组合。
思路: 对于至少与至多的问题,同意化为至多。 对于至少m个g士兵连续={至多n个g士兵连续 -- 至多m-1个g士兵连续},这样就是g的士兵就是在n与m之间。。。
这就转换为求同时满足两个至多条件下的组合次数。
设定一个二维数组dp【M】【3】 。 dp【i】 【0】,dp【i】【1】,dp【i】【2】分别代表第i为g,r,p。
对于当前位置 sum=dp[i-1][0]+dp[i-1][1]+dp[i-1][2];
由于放P对整个没有影响,所以,dp[i][2]=sum;
对于至多n个g士兵连续
当i <= u 时,dp[i][0]=sum; //至多连续u个,那么小于等于u,就可以直接放G
当i==u+1时,dp[i][0]=sum-1; // 对于现在这个位置,之前可能出现连续u个的情况,当前要放G,就要减去那一种情况
当i>u+1时,dp[i][0]=sum-dp[i-u-1][1]-dp[i-u-1][2]; //此时要减去i前面已经出现连续u个G的情况,即从i-u到i-1这一段都是G,那么i-1-u的位置可以是P或者R, //于是减去dp[i-u-1][1],dp[i-1-u][2]合起来总共具有的情况数。
对于至多m-1个g士兵连续
当i<=v时,dp[i][1]=sum;
当i==v+1时,dp[i][1]=sum-1;
当i>v+1时,dp[i][2]=sum-dp[i-v-1][0]-dp[i-v-1][2];
#include<cstdio>using namespace std;typedef long long ll;const int M=1000010;const long long mod=1000000007;ll dp[M][3];int n,m,k;ll solve(int u,int v){ dp[0][0]=1;dp[0][1]=dp[0][2]=0; 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; if(i==u+1) dp[i][0]=(sum-1+mod)%mod; if(i>u+1) dp[i][0]=(sum-dp[i-u-1][1]-dp[i-u-1][2]+mod)%mod; if(i<=v) dp[i][1]=sum; if(i==v+1) dp[i][1]=(sum-1+mod)%mod; if(i>v+1) dp[i][1]=(sum-dp[i-v-1][0]-dp[i-v-1][2]+mod)%mod; } return ((dp[n][0]+dp[n][1]+dp[n][2])%mod+mod)%mod;}int main(){ while(~scanf("%d%d%d",&n,&m,&k)) { printf("%lld\n",((solve(n,k)-solve(m-1,k))%mod+mod)%mod); } return 0;}
- 【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
- Silver Cow Party
- Retrofit和Rxjava的简单了解
- tf-idf:sklearn中TfidfVectorizer使用
- spring-task
- 【Java】split(".")
- Attack on Titans ZOJ
- czl蒻蒟的OI之路2
- server-send node.js实现
- UVA11584[Partitioning by Palindromes] 动态规划
- JVM学习笔记
- jd-eclipse反编译插件的在线安装和使用
- JSON的C语言编解码器——cJSON和json-c
- 515
- java 测试单例中的成员方法是否线程安全