ZOJ - 3725 Painting Storages
来源:互联网 发布:lte寻呼成功率优化 编辑:程序博客网 时间:2024/05/01 15:48
Description
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
题意:n个格子排成一条直线,可以选择涂成红色或蓝色,问最少 m 个连续为红色的方案数。
思路:DP,分两种情况,一种是对于第i个,如果前i-1个已经有了,那么第i个就无所谓了。另一种是加上第i个才能构成m个连续的话,那么第i-m个就是蓝色的,然后让前i-1-m个不包含连续m个的红色。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>typedef long long ll;using namespace std;const int maxn = 100005;const int mod = 1000000007;ll f[maxn], dp[maxn];int n, m;int main() {f[0] = 1;for (int i = 1; i < maxn; i++)f[i] = f[i-1] * 2 % mod;while (scanf("%d%d", &n, &m) != EOF) {if (m > n) {printf("0\n");continue;}memset(dp, 0, sizeof(dp));dp[m] = 1;for (int i = m+1; i <= n; i++) dp[i] = ((dp[i-1] * 2 + f[i-1-m] - dp[i-m-1]) % mod + mod) % mod;printf("%lld\n", dp[n]);}return 0;}
- ZOJ 3725 Painting Storages
- zoj 3725 Painting Storages
- zoj 3725 Painting Storages
- ZOJ - 3725 Painting Storages
- zoj 3725 Painting Storages dp
- ZOJ 3725 Painting Storages DP
- zoj 3725 Painting Storages 题解
- ZOJ 3725 - Painting Storages(DP)
- ZOJ 3725 Painting Storages 解题报告
- zoj 3725 - Painting Storages(动归)
- ZOJ 3725 Painting Storages DP+排列计数
- ZOJ 3725 Painting Storages(DP解排列计数)
- ZOJ 3725 Painting Storages(DP解排列计数)
- [ACM] ZOJ 3725 Painting Storages (DP计数+组合)
- [ACM] ZOJ 3725 Painting Storages (DP计数+组合)
- ZOJ 3725 Painting Storages(很好的dp题)
- Painting Storages
- ZOJ Monthly, June 2013 J 题 Painting Storages
- 马云说:管理不要怕员工离开
- Ubuntu服务器拆硬盘换到别的电脑上找不到网卡
- 十 v4l2驱动文档之——controls
- perl重点学习笔记(一)
- Microsoft.VisualBasic.Devices之Keyboard 类
- ZOJ - 3725 Painting Storages
- 网站制作公司与草根站长的新的“掘金”领域
- Struts2中的OGNL详解
- 《w3school-XML》学习小结
- 太阳能低电压计算机的应用
- 存储过程的好处和一些注意事项!(转)
- [转]Xcode6中自动布局autolayout和sizeclass的使用
- 十一 v4l2驱动文档之——filed
- [编转]Android localsocket 的基础和使用实践: 02