zoj 3747

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;
}
时间: 2025-01-01 21:22:22

zoj 3747的相关文章

[递推dp] zoj 3747 Attack on Titans

题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5170 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 newf

ZOJ 3747 Attack on Titans

Attack on Titans Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ID: 374764-bit integer IO format: %lld      Java class name: Main Over centuries ago, mankind faced a new enemy, the Titans. The difference of powe

zoj 3747 (DP)

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5170 参考: http://blog.csdn.net/cc_again/article/details/24841249 题目意思: 给n个士兵排队,每个士兵三种G.R.P可选,求至少有m个连续G士兵,最多有k个连续R士兵的排列的种数. 一个最多,一个最少很难判断.可以转化成两个最多. 至少有m个 =  取值 m~n =  {最多有n个} - {最多有m-1个} 因为是求总

ACM总结——dp专辑(转)

感谢博主——      http://blog.csdn.net/cc_again?viewmode=list       ----------  Accagain  2014年5月15日 动态规划一直是ACM竞赛中的重点,同时又是难点,因为该算法时间效率高,代码量少,多元性强,主要考察思维能力.建模抽象能力.灵活度. 本人动态规划博客地址:http://blog.csdn.net/cc_again/article/category/1261899 ***********************

【DP专辑】ACM动态规划总结

转载请注明出处,谢谢.   http://blog.csdn.net/cc_again?viewmode=list          ----------  Accagain  2014年5月15日 动态规划一直是ACM竞赛中的重点,同时又是难点,因为该算法时间效率高,代码量少,多元性强,主要考察思维能力.建模抽象能力.灵活度. 本人动态规划博客地址:http://blog.csdn.net/cc_again/article/category/1261899 ******************

dp--递推

Attack on Titans ZOJ - 3747 题意:有三种兵A,B,C,选n个排队,问(至少m个连续的B和至多连续的C)的方案数. 理解了很长时间,,,好菜=_=|| 先贴上代码,有空来写 1 #include <bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 const int maxn = 1000010; 5 const int mod = 1000000007; 6 ll d[maxn][4]; 7

(转)dp动态规划分类详解

dp动态规划分类详解 转自:http://blog.csdn.NET/cc_again/article/details/25866971 动态规划一直是ACM竞赛中的重点,同时又是难点,因为该算法时间效率高,代码量少,多元性强,主要考察思维能力.建模抽象能力.灵活度. ****************************************************************************************** 动态规划(英语:Dynamic programm

这个是转的。学完就删_(:з」∠)_

原文链接:http://blog.csdn.net/cc_again/article/details/25866971 好多dp:http://blog.csdn.net/cc_again/article/category/1261899 一.简单基础dp 这类dp主要是一些状态比较容易表示,转移方程比较好想,问题比较基本常见的.主要包括递推.背包.LIS(最长递增序列),LCS(最长公共子序列),下面针对这几种类型,推荐一下比较好的学习资料和题目. 1.递推: 递推一般形式比较单一,从前往后,

概率dp ZOJ 3640

Help Me Escape Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3640 Appoint description:  System Crawler  (2014-10-22) Description Background     If thou doest well, shalt thou not be accepted? an