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. [BZOJ4537][HNOI2016]最小公倍数(分块+并查集)

    4537: [Hnoi2016]最小公倍数 Time Limit: 40 Sec  Memory Limit: 512 MBSubmit: 1687  Solved: 607[Submit][Stat ...

  2. Java本地方法(native方法)的实现

    Java不是完美的,Java的不足除了体现在运行速度上要比传统的C++慢许多之外,Java无法直接访问到操作系统底层(如系统硬件等),为此Java使用native方法来扩展Java程序的功能. 可以将 ...

  3. [转]详解spring 每个jar的作用

    spring.jar 是包含有完整发布模块的单个jar 包.但是不包括mock.jar, aspects.jar, spring-portlet.jar, and spring-hibernate2. ...

  4. CentOS 6.9配置网卡IP/网关/DNS命令详细介绍及一些常用网络配置命令(转)

    一.IP 即时生效(重启后失效): ifconfig eth0 192.168.1.102 netmask 255.255.255.0 //添加IP地址 route add default gw 19 ...

  5. go排序后索引

    最近碰上了一个需求,要得到排序后的原索引序列. 我又不希望自己重新实现一快排出来,所以在接口上重新封装了一下. package main import ( "fmt" " ...

  6. 【转】记录PHP、MySQL在高并发场景下产生的一次事故

    看了一篇网友日志,感觉工作中值得借鉴,原文如下: 事故描述 在一次项目中,上线了一新功能之后,陆陆续续的有客服向我们反应,有用户的个别道具数量高达42亿,但是当时一直没有到证据表示这是,确实存在,并且 ...

  7. 认识udev

    转:http://www.360doc.com/content/11/0415/21/1317564_109923795.shtml 因为本身从事存储行业,在工作中多次碰到用户有这样的要求:我的lin ...

  8. Netty游戏服务器之一

    所谓磨刀不误砍柴工,所以在搭建netty游戏服务器之前,我们先要把要准备的东西做好. 首先进入netty的官网下载最新版本的netty的jar包,http://netty.io/downloads.h ...

  9. javascript 获取http头信息

    Javascript中跟response header有关的就两个方法: getResponseHeader 从响应信息中获取指定的http头 语法 strValue = oXMLHttpReques ...

  10. 白话空间统计之:Moran&#39;s I(莫兰指数)

    前两天聊了空间统计学里面的两个经典概念,今天来说说第一篇文章留下的大坑:Moran's I. 首先,Moran's I这个东西.官方叫做:莫兰指数,是澳大利亚统计学家帕特里克·阿尔弗雷德·皮尔斯·莫兰 ...