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&ltN, 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的更多相关文章

  1. [ACM] ZOJ 3725 Painting Storages (DP计数+组合)

    Painting Storages Time Limit: 2 Seconds      Memory Limit: 65536 KB There is a straight highway with ...

  2. zoj 3725 - Painting Storages(动归)

    题目要求找到至少存在m个连续被染成红色的情况,相对应的,我们求至多有m-1个连续的被染成红色的情况数目,然后用总的数目将其减去是更容易的做法. 用dp来找满足条件的情况数目,, 状态:dp[i][0] ...

  3. ZOJ 3725 Painting Storages(DP+排列组合)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5048 Sample Input 4 3 Sample Output ...

  4. Painting Storages(ZOJ)

    There is a straight highway with N storages alongside it labeled by 1,2,3,...,N. Bob asks you to pai ...

  5. zoj 3725

    题意: n个格子排成一条直线,可以选择涂成红色或蓝色,问最少 m 个连续为红色的方案数. 解题思路: 应该是这次 ZOJ 月赛最水的一题,可惜还是没想到... dp[i] 表示前 i 个最少 m 个连 ...

  6. ZOJ-3725 Painting Storages DP

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3725 n个点排列,给每个点着色,求其中至少有m个红色的点连续的数 ...

  7. ZOJ-3725 Painting Storages 动态规划

    题意:给定一个数N,表示有N个位置,要么放置0,要么放置1,问至少存在一个连续的M个1的放置方式有多少? 分析:正面求解可能还要考虑到重复计算带来的影响,该题适应反面求解.设dp[i][j]表示到前 ...

  8. 130804组队练习赛ZOJ校赛

    A.Ribbon Gymnastics 题目要求四个点作圆,且圆与圆之间不能相交的半径之和的最大值.我当时想法很简单,只要两圆相切,它们的半径之和一定最大,但是要保证不能相交的话就只能取两两个点间距离 ...

  9. zoj 1610 Count the Colors

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=610  Count the Colors Time Limit:2000MS   ...

随机推荐

  1. 【计算几何】【预处理】【枚举】Urozero Autumn Training Camp 2016 Day 5: NWERC-2016 Problem K. Kiwi Trees

    发现由于角的度数和边的长度有限制,那俩圆如果放得下的话,必然是塞在两个角里. 于是预处理n个圆心的位置(注意要判断那个圆会不会和其他的边界相交),然后n^2枚举俩角即可. #include<cs ...

  2. 【可持久化数组】【rope】bzoj3673 bzoj3674 可持久化并查集 by zky

    rope教程:http://blog.csdn.net/iamzky/article/details/38348653 Code(bzoj3673): #include<cstdio> # ...

  3. Trie 图

    时间限制:20000ms 单点时限:1000ms 内存限制:512MB 描述 前情回顾 上回说到,小Hi和小Ho接受到了河蟹先生伟大而光荣的任务:河蟹先生将要给与他们一篇从互联网上收集来的文章,和一本 ...

  4. kindeditor在Firefoxt 和 Chrome 下不能取到值的解决方法

    默认form模式提交数据的时候,在ie下用户不需要进行任何设置和调用sync函数,因为editor已经自动调用,但是在firefox和 chrome下,用户如果不手动调用sync函数,editor的数 ...

  5. MYSQL复习笔记4-基本SQL语句

    Date: 20140115Auth: Jin参考:http://dev.mysql.com/doc/refman/5.1/zh/sql-syntax.html#select一:数据库操作1:显示数据 ...

  6. 黑莓10开发101:Native平台

    为黑莓10开发游戏或应用程序有多种方法.这是件好事,不过如果你不是在黑莓平台下进行开发,或者你仅熟悉基于旧的Java的开发平台,也许你会感到无所适从.你将作何选择?从哪里着手? 促成你做出决定的因素有 ...

  7. BOOST 实用手册(摘录自校友博客)

    1. 序言 现在学的东西很容易忘记,写这篇文章的目的是能让我在需要时快速找回当时的感觉.  Let's BOOST THE WORLD . 2. 编译:VC2005注意 在 属性->C/C++- ...

  8. CFR Java Decompiler 反编译

    java反编译,JAD & CFR 目前我们开发中大都使用JAD进行java反编译.这个工具已经过于陈旧,最突出的问题就是经常反编译出错. 使用CFR反编译工具能够很好的解决这个问题,并且支持 ...

  9. Neural Networks for Machine Learning by Geoffrey Hinton (4)

    一种能够学习家谱关系的简单神经网络 血缘一共同拥有12种关系: son, daughter, nephew, niece, father, mother, uncle, aunt, brother, ...

  10. ylbtech-LanguageSamples-Pinvoke(平台调用)

    ylbtech-Microsoft-CSharpSamples:ylbtech-LanguageSamples-Pinvoke(平台调用) 1.A,示例(Sample) 返回顶部 “平台调用”示例 本 ...