Painting Storages(ZOJ)
There is a straight highway with N storages alongside it labeled by 1,2,3,...,N. Bob asks you to paint all storages with two colors: red and blue. Each storage will be painted with exactly one color.
Bob has a requirement: there are at least M continuous storages (e.g. "2,3,4" are 3 continuous storages) to be painted with red. How many ways can you paint all storages under Bob's requirement?
Input
There are multiple test cases.
Each test case consists a single line with two integers: N and M (0<N, M<=100,000).
Process to the end of input.
Output
One line for each case. Output the number of ways module 1000000007.
Sample Input
4 3
Sample Output
3
#include <stdio.h>
#include <string.h>
const int N = 1e5 + ;
const int mod = 1e9 + ;
int dp[N],pow[N]= {}; int main()
{
int n,m;
for(int i=; i<N; i++) pow[i] = pow[i-] * % mod;
while(~scanf("%d%d",&n,&m))
{
memset(dp,,sizeof(int)*m);
dp[m] = ;
for(int i=m+; i<=n; i++) dp[i] = ((dp[i-]* % mod + pow[i-m-]-dp[i-m-]) % mod + mod) % mod;
printf("%d\n",dp[n]);
}
return ;
}
数论(排列组合)
Painting Storages(ZOJ)的更多相关文章
- ZOJ 3725 Painting Storages(DP+排列组合)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5048 Sample Input 4 3 Sample Output ...
- [ACM] ZOJ 3725 Painting Storages (DP计数+组合)
Painting Storages Time Limit: 2 Seconds Memory Limit: 65536 KB There is a straight highway with ...
- POJ 1274 The Perfect Stall || POJ 1469 COURSES(zoj 1140)二分图匹配
两题二分图匹配的题: 1.一个农民有n头牛和m个畜栏,对于每个畜栏,每头牛有不同喜好,有的想去,有的不想,对于给定的喜好表,你需要求出最大可以满足多少头牛的需求. 2.给你学生数和课程数,以及学生上的 ...
- ZOJ - 3725 Painting Storages
Description There is a straight highway with N storages alongside it labeled by 1,2,3,...,N. Bob ask ...
- zoj 3725 - Painting Storages(动归)
题目要求找到至少存在m个连续被染成红色的情况,相对应的,我们求至多有m-1个连续的被染成红色的情况数目,然后用总的数目将其减去是更容易的做法. 用dp来找满足条件的情况数目,, 状态:dp[i][0] ...
- CF448C Painting Fence (分治递归)
Codeforces Round #256 (Div. 2) C C. Painting Fence time limit per test 1 second memory limit per tes ...
- ZOJ 4010 Neighboring Characters(ZOJ Monthly, March 2018 Problem G,字符串匹配)
题目链接 ZOJ Monthly, March 2018 Problem G 题意 给定一个字符串.现在求一个下标范围$[0, n - 1]$的$01$序列$f$.$f[x] = 1$表示存在一种 ...
- POJ 1595 Prime Cuts (ZOJ 1312) 素数打表
ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=312 POJ:http://poj.org/problem?id=159 ...
- POJ 2590 Steps (ZOJ 1871)
http://poj.org/problem?id=2590 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1871 题目大 ...
随机推荐
- SQL Server中in与exist效率比较
in和exists in 是把外表和内表作hash 连接,而exists是对外表作loop循环,每次loop循环再对内表进行查询. 一直以来认为exists比in效率高的说法是不准确的. 如果查询的两 ...
- 在Unicode版Inno Setup中使用ISSkin给安装程序添加皮肤
原文 http://www.cnblogs.com/2356/archive/2009/10/27/1590565.html 在Unicode版Inno Setup中使用ISSkin给安装程序添加皮肤 ...
- 封装fastjson为spring mvc的json view
可以将其中的main方法删掉.测试用的.我测试的结果是,jackson比fastjson快. fastjson是1.1.36 jackson是2.2.3 jdk是1.7.40,client cpu是i ...
- [转载]CTO和技术总监区别
原文地址:http://blog.sina.com.cn/s/blog_6024cfa90101cb0h.html 技术总监(Chief Technical Officer)与CTO(Chief Te ...
- Geoserver基本使用、WMS服务发布与OpenLayers测试
1.Geoserver与OpenLayers的下载 Geoserver:http://geoserver.org/ OpenLayers:http://openlayers.org/ 2.安装部署Ge ...
- OC基础14:使用文件
"OC基础"这个分类的文章是我在自学Stephen G.Kochan的<Objective-C程序设计第6版>过程中的笔记. 1.对于NSFileManager类,文件 ...
- apache端口被占用
1.80端口被占用,先去服务里将IIS关闭掉,然后重启apache,如果还是继续弹窗the requested operation has failed...需要去Internet信息服务里面停止 ...
- Python学习入门基础教程(learning Python)--5 Python文件处理
本节主要讨论Python下的文件操作技术. 首先,要明白为何要学习或者说关系文件操作这件事?其实道理很简单,Python程序运行时,数据是存放在RAM里的,当Python程序运行结束后数据从RAM被清 ...
- Time.deltaTime和Time.realtimeSinceStartup
private float f = 0f;void Update () { f += Time.deltaTime; Debug.LogError ("Time.delt ...
- 网络视频传输的服务质量(QoS)
QoS(Qualityof Service)服务质量,是网络的一种安全机制, 是用来解决网络延迟和阻塞等问题的一种技术.在正常情况下,如果网络只用于特定的无时间限制的应用系统,并不需要QoS,比如We ...