const int MAXN = 1100000; int n, m, dp[MAXN], psm[MAXN], f[MAXN]; int main() { f[0] = 1; FF(i, 1, MAXN) f[i] = f[i - 1] * 2 % MOD; while (~RII(n, m)) { dp[0] = psm[0] = 1; FE(i, 1, n + 1) { dp[i] = psm[i - 1]; if (i - m - 1 >= 0) dp[i] = ((dp[i] - psm[i - m - 1]) % MOD + MOD) % MOD; psm[i] = (psm[i - 1] + dp[i]) % MOD; } cout << ((f[n] - dp[n + 1]) % MOD + MOD) % MOD << endl; } return 0; }
原文地址:http://blog.csdn.net/wty__/article/details/38126103