(DP) zoj 3725

Painting Storages


Time Limit: 2 Seconds      Memory Limit: 65536 KB


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

题目:

dp[i]表示 前i个箱子 图m种颜色 的种类,dp[i-1]*2,如果 前i-1符合,否则,i-m一定是蓝色,i-m-1之前不能有红色,2的i-m-1-dp[i-m-1]
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
#define N 100010
const int MOD=1000000007;
int dp[N],n,m,poww[N];
int main()
{
      poww[0]=1;
      for(int i=1;i<N;i++)
            poww[i]=poww[i-1]*2%MOD;
      while(scanf("%d%d",&n,&m)!=EOF)
      {
            memset(dp,0,sizeof(dp));
            dp[m]=1;
            for(int i=m+1;i<=n;i++)
            {
                 dp[i]=((dp[i-1]*2%MOD+poww[i-m-1]-dp[i-m-1])%MOD+MOD)%MOD;
            }
            printf("%d\n",dp[n]);
      }
      return 0;
}

  

时间: 2024-08-25 00:24:21

(DP) zoj 3725的相关文章

[dp] zoj 3769 Diablo III

题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3769 Diablo III Time Limit: 2 Seconds      Memory Limit: 65536 KB Diablo III is an action role-playing video game. A few days ago, Reaper of Souls (ROS), the new expansion of Diablo I

[dp] zoj 3740 Water Level

题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5122 Water Level Time Limit: 2 Seconds      Memory Limit: 65536 KB Hangzhou is a beautiful city, especially the West Lake. Recently, the water level of the West Lake got lower and lower

[递推dp] zoj 3747 Attack on Titans

题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5170 Attack on Titans Time Limit: 2 Seconds      Memory Limit: 65536 KB Over centuries ago, mankind faced a new enemy, the Titans. The difference of power between mankind and their newf

[dp] zoj 3682 E - Cup 3

题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3682 E - Cup 3 Time Limit: 3 Seconds      Memory Limit: 65536 KB The 2012 Europe Cup was over and Spain won the Championship. The fans of Spain want to hold some activities to celebra

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

Painting Storages Time Limit: 2 Seconds      Memory Limit: 65536 KB 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 e

概率dp ZOJ 3640

Help Me Escape Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3640 Appoint description:  System Crawler  (2014-10-22) Description Background     If thou doest well, shalt thou not be accepted? an

(状态压缩DP) zoj 3471

T - Most Powerful Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3471 Appoint description:  System Crawler  (2015-04-16) Description Recently, researchers on Mars have discovered N powerful atoms

状压DP [ZOJ 3471] Most Powerful

Most Powerful Time Limit: 2 Seconds      Memory Limit: 65536 KB Recently, researchers on Mars have discovered N powerful atoms. All of them are different. These atoms have some properties. When two of these atoms collide, one of them disappears and a

DP ZOJ 3872 Beauty of Array

题目传送门 1 /* 2 DP:dp 表示当前输入的x前的包含x的子序列的和, 3 求和方法是找到之前出现x的位置(a[x])的区间内的子序列: 4 sum 表示当前输入x前的所有和: 5 a[x] 表示id: 6 详细解释:http://blog.csdn.net/u013050857/article/details/45285515 7 */ 8 #include <cstdio> 9 #include <algorithm> 10 #include <cmath>