标签:
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?
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.
One line for each case. Output the number of ways module 1000000007.
4 3
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; }
标签:
原文地址:http://www.cnblogs.com/a972290869/p/4273614.html