码迷,mamicode.com
首页 > 其他好文 > 详细

zoj 3747

时间:2014-09-03 09:44:47      阅读:297      评论:0      收藏:0      [点我收藏+]

标签:style   color   os   io   strong   ar   for   cti   代码   

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.


AC代码:

#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
#define ll long long
ll sum;
ll f[1000005][3];
int main(){
    ll n,m,k;
    while(cin>>n>>m>>k){
        int u,v;
        u=n; v=k;
        f[0][0]=1; f[0][1]=f[0][2]=0;
        for(int i=1;i<=n;i++){
            if(i<=u)
                f[i][0]=(f[i-1][0]+f[i-1][1]+f[i-1][2])%1000000007;
            else if(i==u+1)
                f[i][0]=(f[i-1][0]+f[i-1][1]+f[i-1][2]-1)%1000000007;
            else
                f[i][0]=(f[i-1][0]+f[i-1][1]+f[i-1][2]-f[i-u-1][1]-f[i-u-1][2])%1000000007;

            if(i<=v)
                f[i][1]=(f[i-1][0]+f[i-1][1]+f[i-1][2])%1000000007;
            else if(i==v+1)
                f[i][1]=(f[i-1][0]+f[i-1][1]+f[i-1][2]-1)%1000000007;
            else
                f[i][1]=(f[i-1][0]+f[i-1][1]+f[i-1][2]-f[i-v-1][0]-f[i-v-1][2])%1000000007;

            f[i][2]=(f[i-1][0]+f[i-1][1]+f[i-1][2])%1000000007;
        }
        sum=(f[n][0]+f[n][1]+f[n][2])%1000000007;

        u=m-1; v=k;
        for(int i=1;i<=n;i++){
            if(i<=u)
                f[i][0]=(f[i-1][0]+f[i-1][1]+f[i-1][2])%1000000007;
            else if(i==u+1)
                f[i][0]=(f[i-1][0]+f[i-1][1]+f[i-1][2]-1)%1000000007;
            else
                f[i][0]=(f[i-1][0]+f[i-1][1]+f[i-1][2]-f[i-u-1][1]-f[i-u-1][2])%1000000007;

            if(i<=v)
                f[i][1]=(f[i-1][0]+f[i-1][1]+f[i-1][2])%1000000007;
            else if(i==v+1)
                f[i][1]=(f[i-1][0]+f[i-1][1]+f[i-1][2]-1)%1000000007;
            else
                f[i][1]=(f[i-1][0]+f[i-1][1]+f[i-1][2]-f[i-v-1][0]-f[i-v-1][2])%1000000007;

            f[i][2]=(f[i-1][0]+f[i-1][1]+f[i-1][2])%1000000007;
        }
        ll tmp=(f[n][0]+f[n][1]+f[n][2])%1000000007;
        cout<<((sum-tmp)%1000000007+1000000007)%1000000007<<endl;
    }
    return 0;
}


zoj 3747

标签:style   color   os   io   strong   ar   for   cti   代码   

原文地址:http://blog.csdn.net/my_acm/article/details/39012609

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!