zoj 3747 递推dp
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.
题解:https://blog.csdn.net/papapa_swust/article/details/77745984
#include <iostream>
#include <cstdio> const int N = +;
const int mod = 1e9+;
typedef long long ll;
int n,m,k; ll dp[N][]; ll _mod(ll x)
{
x %= mod;
x = (x+mod)%mod;
return x;
} ll cal(int u,int v)
{
dp[][]=,dp[][]=,dp[][]=;
for(int i=;i<=n;i++)
{
ll sum= (dp[i-][]+dp[i-][]+dp[i-][])%mod;
dp[i][] = sum;
if(i <= u)
dp[i][] = sum;
//else if(i == u+1)
//dp[i][0] = _mod(sum-1);
else
dp[i][] = _mod(sum - dp[i-u-][]-dp[i-u-][]);
if(i <= v)
dp[i][] = sum;
//else if(i == v+1)
//dp[i][1] = _mod(sum-1);
else
dp[i][] = _mod(sum - dp[i-v-][]-dp[i-v-][]);
}
return _mod(dp[n][]+dp[n][]+dp[n][]);
} int main ()
{ while (scanf("%d%d%d",&n,&m,&k)==)
{
printf("%lld\n",_mod(cal(n,k)-cal(m-,k)));
}
return ;
}
zoj 3747 递推dp的更多相关文章
- 递推DP URAL 1167 Bicolored Horses
题目传送门 题意:k个马棚,n条马,黑马1, 白马0,每个马棚unhappy指数:黑马数*白马数,问最小的unhappy值是多少分析:dp[i][j] 表示第i个马棚放j只马的最小unhappy值,状 ...
- 递推DP URAL 1017 Staircases
题目传送门 /* 题意:给n块砖头,问能组成多少个楼梯,楼梯至少两层,且每层至少一块砖头,层与层之间数目不能相等! 递推DP:dp[i][j] 表示总共i块砖头,最后一列的砖头数是j块的方案数 状态转 ...
- 递推DP URAL 1260 Nudnik Photographer
题目传送门 /* 递推DP: dp[i] 表示放i的方案数,最后累加前n-2的数字的方案数 */ #include <cstdio> #include <algorithm> ...
- 递推DP URAL 1353 Milliard Vasya's Function
题目传送门 /* 题意:1~1e9的数字里,各个位数数字相加和为s的个数 递推DP:dp[i][j] 表示i位数字,当前数字和为j的个数 状态转移方程:dp[i][j] += dp[i-1][j-k] ...
- 递推DP URAL 1119 Metro
题目传送门 /* 题意:已知起点(1,1),终点(n,m):从一个点水平或垂直走到相邻的点距离+1,还有k个抄近道的对角线+sqrt (2.0): 递推DP:仿照JayYe,处理的很巧妙,学习:) 好 ...
- 递推DP 赛码 1005 Game
题目传送门 /* 递推DP:官方题解 令Fi,j代表剩下i个人时,若BrotherK的位置是1,那么位置为j的人是否可能获胜 转移的时候可以枚举当前轮指定的数是什么,那么就可以计算出当前位置j的人在剩 ...
- 递推DP HDOJ 5328 Problem Killer
题目传送门 /* 递推DP: 如果a, b, c是等差数列,且b, c, d是等差数列,那么a, b, c, d是等差数列,等比数列同理 判断ai-2, ai-1, ai是否是等差(比)数列,能在O( ...
- hdu1978(递推dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1978 分析: 递推DP. dp[][]表示可以到达改点的方法数. 刚开始:外循环扫描所有点dp[x][ ...
- 递推DP URAL 1031 Railway Tickets
题目传送门 /* 简单递推DP:读题烦!在区间内的都更新一遍,dp[]初始化INF 注意:s1与s2大小不一定,坑! 详细解释:http://blog.csdn.net/kk303/article/d ...
随机推荐
- 单例模式与静态变量在PHP中 (转载)
在PHP中,没有普遍意义上的静态变量.与Java.C++不同,PHP中的静态变量的存活周期仅仅是每次PHP的会话周期,所以注定了不会有Java或者C++那种静态变量. 所以,在PHP中,静态变量的存在 ...
- 2.实现官网环境, 搭建HTTP服务器
1.建立 HTTP 服务器 Node.js 是为网络而诞生的平台,但又与 ASP.PHP 有很大的不同,究竟不同在哪里呢?如果你有 PHP 开发经验,会知道在成功运行 PHP 之前先要配置一个功能强大 ...
- 记录web项目部署到阿里云服务器步骤
(使用 web项目.阿里云服务器.Xftp.Xshell),敬请参考和指正 1.将要部署的项目打包成WAR文件格式,可以在MyEclipse.Eclipse都可以完成打包,如下图: 2.安装Xshel ...
- Jmeter性能测试实践之java请求
前言 Apache Jmeter是开源.易用的性能测试工具,之前工作中用过几次对http请求进行性能测试,对jmeter的基本操作有一些了解.最近接到开发的对java请求进行性能测试的需求,所以需要 ...
- MySQL实现根据当前ID读取上一条和下一条记录
以下为MySQL语句演示: SELECT * FROM t_news AS n ORDER BY n.`News_ID` 当前ID为4,读取上一条记录: ,; 当前ID为4,读取下一条记录: ,; 其 ...
- 原来css可以直接覆盖内联style
今天阅读博文新手如何在gdb中存活时,发现行距太小,阅读起来不舒服. 查看了一下html代码,发现是博文内容中的内联style(line-height: normal)覆盖了博客模板的css引起的. ...
- PL/SQL编程基础(二):变量的声明、赋值、(赋值、连接、关系、逻辑)运算符
变量的声明.赋值.运算符 1.声明并使用变量 变量可以在声明时赋值,也可以先定义后赋值: 使用%TYPE与%ROWTYPE可以根据已有类型定义变量. PL/SQL是一种强类型的编程语言,所有的变量都必 ...
- Python爬虫框架Scrapy实例(二)
目标任务:使用Scrapy框架爬取新浪网导航页所有大类.小类.小类里的子链接.以及子链接页面的新闻内容,最后保存到本地. 大类小类如下图所示: 点击国内这个小类,进入页面后效果如下图(部分截图): 查 ...
- 原!上线遇到的问题, java序列化关键字transient 修饰的属性变成null了
1.问题描述: 某个功能点,user对象 放入session,后再另外地方取出,结果某个字段没有了.再本地和测试环境都是ok的,但是线上环境就是不行. 后来看到这个user对象的那个属性是加了tran ...
- Log表新的RowKey设计,预Split
1 目前Rawlog表的问题 region数量庞大,空region 率大 共有12791个region 11409空region, 比例为89.19% 剩余的region大小也是极度不均衡,最大的re ...