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)的更多相关文章

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

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

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

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

  3. POJ 1274 The Perfect Stall || POJ 1469 COURSES(zoj 1140)二分图匹配

    两题二分图匹配的题: 1.一个农民有n头牛和m个畜栏,对于每个畜栏,每头牛有不同喜好,有的想去,有的不想,对于给定的喜好表,你需要求出最大可以满足多少头牛的需求. 2.给你学生数和课程数,以及学生上的 ...

  4. ZOJ - 3725 Painting Storages

    Description There is a straight highway with N storages alongside it labeled by 1,2,3,...,N. Bob ask ...

  5. zoj 3725 - Painting Storages(动归)

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

  6. CF448C Painting Fence (分治递归)

    Codeforces Round #256 (Div. 2) C C. Painting Fence time limit per test 1 second memory limit per tes ...

  7. ZOJ 4010 Neighboring Characters(ZOJ Monthly, March 2018 Problem G,字符串匹配)

    题目链接  ZOJ Monthly, March 2018 Problem G 题意  给定一个字符串.现在求一个下标范围$[0, n - 1]$的$01$序列$f$.$f[x] = 1$表示存在一种 ...

  8. POJ 1595 Prime Cuts (ZOJ 1312) 素数打表

    ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=312 POJ:http://poj.org/problem?id=159 ...

  9. POJ 2590 Steps (ZOJ 1871)

    http://poj.org/problem?id=2590 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1871 题目大 ...

随机推荐

  1. Python信息采集器使用轻量级关系型数据库SQLite

    1,引言Python自带一个轻量级的关系型数据库SQLite.这一数据库使用SQL语言.SQLite作为后端数据库,可以搭配Python建网站,或者为python网络爬虫存储数据.SQLite还在其它 ...

  2. knockout简单实用教程2

    在上一篇文章中简单了介绍了下什么ko(后文中都已ko来代替knockout.js)和一些简单的ko的使用方法下面我将介绍在实际的项目中常用到的几种绑定方式和方法. 在开始之前先拿一个dome来回顾下k ...

  3. 关于Asp.net超时,延长读取sql server数据库的超时时间!(已解决)

    昨天,接到客户反映说应用报“超时时间已到.在操作完成之前超时时间已过或服务器未响应”问题.从网上了一些资料,发现这个问题还是很普遍的.主要有以下两种解决方法: 第一种方法:在web.config中加上 ...

  4. eclipse 常用的一些设置

    1.行长度设置 http://blog.csdn.net/janronehoo/article/details/10047937 2.字体 windows -> preference -> ...

  5. URL组成介绍

    1.2. HTTP request ----------------- First, let's consider this HTTP request : Line Contents number 1 ...

  6. zabbix 组信息

    mysql> select * from groups; +---------+------------------+----------+-------+ | groupid | name | ...

  7. hdu 5569 matrix(简单dp)

    Problem Description Given a matrix with n rows and m columns ( n+m ,) and you want to go to the numb ...

  8. iOS 四种延时的方法

    - (void)initBlock{     //延时的方法     //1:GCD延时 此方式在能够在參数中选择运行的线程. 是一种非堵塞的运行方式,没有找到取消运行的方法.     double ...

  9. GCC单独编译host/examples/ tx_waveforms.cpp

    1.编译 须要链接uhd库和boost_program_options库以及boost_thread库: g++ tx_waveforms.cpp -o a -luhd -lboost_program ...

  10. (转)12款开源JavaScript库

    JavaScipt几乎是所有前端开发人员必会的编程语言,并且,随着各种移动APP的串红,JavaScript还可以用来开发移动应用.除此以外,为了丰富前端/移动开发,有不少开发者推出了各种基于Java ...