ZOJ 3747 Attack on Titans

Source: Internet
Author: User

Attack on Titanstime limit:2000msmemory limit:65536kbthis problem would be judged onZju. Original id:3747
64-bit integer IO format: %lld Java class name: Main

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 were pushed back to Wall Rose. Then mankind began to realize, hiding behind the walls equaled to death and they should manage a attack on the titans.

So, Captain Levi, the strongest ever human being, is ordered to set up a special Operation squad of  N & Nbsp;people, numbered from  1  to  N . Each number should is assigned to a soldier. There is three corps that the soldiers come from:the garrison, the Recon Corp and the Military Police. While the garrison is stationed at the walls and defend the cities, the Recon Corps put their lives on the Lin E 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'll take advantage of the differences between the corps and some conditions Must be met.

The garrisons is good at team work, so Levi wants there to be at least M garrison members assigned with continuous NU Mbers. On the other hand, members of the Recon Corp is 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 all members in each Corp., Levi wants to know how many ways there was to arrange the Specia L Operation squad.

Input

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

Output

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.

SourceZOJ Monthly, January 2014AuthorZOU, Xun problem solving: Very good DP problem, see accagain problem solving ideas to understand can also do this topic is: to n soldiers in line, each soldier three kinds G, R, p optional, for at least m a continuous G soldier, up to K continuous R soldiers of the arrangement of the number of species. We can first find out that there are n consecutive G soldiers, up to a continuous number of K R soldiers and then subtract up to m-1 a continuous G soldier, up to a continuous K R soldiers of the permutation of the number of the difference is that we ask for at least m continuous g soldiers, up to K continuous R soldier arrangement number But now how to find out the maximum number of u continuous G soldiers and up to V Continuous R Soldier Arrangement Scheme we can make dp[i][0] represent up to u a continuous G soldier and the first I is gdp[i][1] for up to V continuous R soldier, and the first soldier is R soldier Dp[i][2] That is to say that I is a P soldier when I <= u, it is clear that dp[i][0] = dp[i-1][0] + dp[i-1][1] + dp[i-1][2) does not close the i-1 bit is what class, will not cause G soldiers over the constraint number when i = U + 1 o'clock, we want to expel a situation is 1 to u are the case of G, if at this time in the U + 1th position g soldier, G soldier number will be greater than u therefore when the transfer equation is dp[i][0] = dp[i-1][0] + dp[i-1][1] + dp[i-1][2]-1; when i > U + 1 o'clock, we What's the most worrying thing? I-1 to I-u are G soldiers, so at this point in the position of the G soldier, will not be bound we can subtract the number of non-conforming scenarios, when the i-1 to i-u are G soldiers when the number of options? Certainly when I-u-1 is R or P-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] Similar transfer equations can be introduced dp[i][1]
1#include <bits/stdc++.h>2 using namespacestd;3typedefLong LongLL;4 Const intMoD =1000000007;5 Const intMAXN =2000010;6LL dp[maxn][3];7 intn,m,k;8LL Solve (intUintv) {9dp[0][0] =1;Tendp[0][1] = dp[0][2] =0; One      for(inti =1; I <= N; ++i) { ALL 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; the         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; A } at intMain () { -      while(~SCANF ("%d%d%d",&n,&m,&k)) -printf"%lld\n", ((Solve (n,k)-Solve (M-1, k))%mod + MoD)%MoD); -     return 0; -}
View Code

ZOJ 3747 Attack on Titans

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.