码迷,mamicode.com
首页 > 其他好文 > 详细

(DP) zoj 3725

时间:2015-02-05 00:38:04      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:

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;
}

  

(DP) zoj 3725

标签:

原文地址:http://www.cnblogs.com/a972290869/p/4273614.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!