Attack on Titans_dp递推

原创 2018年04月15日 18:20:42

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<bits/stdc++.h>
#include<cstring>
#include<vector>
#include<algorithm>
#include<iostream>

using namespace std;

const int N=1e6+10;

#define ll long long
#define rep(i,n) for(int i=1;i<=n;i++)
#define red(i,n) for(int i=n;i>=1;i--)
const int mod=1e9+7;
ll dp[N][3];//G,R,P

int n,m,k;

int cal(int g,int r){
    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<=g)dp[i][0]=sum;
        else dp[i][0]=(sum-dp[i-g-1][2]-dp[i-g-1][1]+2*mod)%mod;
        if(i<=r)dp[i][1]=sum;
        else dp[i][1]=(sum-dp[i-r-1][2]-dp[i-r-1][0]+2*mod)%mod;
    }
    return (dp[n][0]+dp[n][1]+dp[n][2])%mod;
}

int main(){
    freopen("in.txt","r",stdin);
    while(~scanf("%d%d%d",&n,&m,&k))
    printf("%d\n",(cal(n,k)-cal(m-1,k)+mod)%mod);
    fclose(stdin);
}




版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ujn20161222/article/details/79951574

验证时间攻击 Verification Timing Attack

验证时间攻击 Verification Timing Attack 一种感觉比较另类的碰撞tag的方式,主要是利用服务端的反馈时间。 比如:攻击者想上传个文件给服务器,苦于无法得到该文件相应的Ta...
  • jerry81333
  • jerry81333
  • 2016-10-09 09:27:44
  • 543

CSAPP:Attack Lab —— 缓冲区溢出攻击实验

CSAPP:Attack Lab —— 缓冲区溢出攻击实验 X86-64寄存器和栈帧 Part I:Code Injection Attacks Part II:Return-Oriented Pr...
  • qq_36894564
  • qq_36894564
  • 2017-06-05 00:44:34
  • 1425

IP排序,按照自然数

  • 2014年08月19日 12:14
  • 7KB
  • 下载

CSAPP 3e Attack lab

总结一下CSAPP第三版的attack lab。
  • lijun538
  • lijun538
  • 2016-02-17 21:55:27
  • 24396

Injection Attack

Injection Attacks The OWASP Top 10 lists Injection and Cross-Site Scripting (XSS) as the most com...
  • boer521314
  • boer521314
  • 2015-02-01 13:00:13
  • 1286

Slow HTTP Denial of Service Attack

整改建议   1.中断使用URL不支持HTTP方法访问的会话   2.限制HTTP头及包长至一个合理数值   3.设置一个绝对的会话超时时间   4.服务器支持backlog的情况下,需设置一...
  • meiru8
  • meiru8
  • 2014-08-21 10:16:16
  • 8843

Length Extension Attack

在做plaidctf时遇到了这个,记录下吧。
  • u011500307
  • u011500307
  • 2014-04-19 11:59:35
  • 1798

ZOJ 3747 Attack on Titans

Attack on Titans Time Limit: 2 Seconds      Memory Limit: 65536 KB Over centuries ago, mankind fa...
  • wust_ZJX
  • wust_ZJX
  • 2015-07-08 22:36:40
  • 987

中this computer is being attack后,好多格式的文件或者程序都不能运行的解决

一个多月前,电脑中毒,一直有个”this computer is being attack“弹来弹去,杀毒后,好多格式的文件或者程序都不能运行了。 解决:  开始——regedit——打开注册表 ...
  • lrf8682004
  • lrf8682004
  • 2014-02-03 08:53:07
  • 452

Web安全 Buffer Overflow Attack实验

Assignment 7  Buffer Overflow Attack 一开始我直接复制粘贴了蔡老师的代码,结果一直得不到预期的输出,但是之后我再看了看蔡老师的课...
  • zaxguo
  • zaxguo
  • 2014-11-20 23:04:24
  • 451
收藏助手
不良信息举报
您举报文章:Attack on Titans_dp递推
举报原因:
原因补充:

(最多只允许输入30个字)