CodeForces 474D Flowers (dp)

dp[i]表示有i朵花时,有多少种吃法

那么dp[i]=dp[i-1]+dp[i-k];dp[i-1]再吃朵红,dp[i-k]再吃k朵白

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define CPY(A, B) memcpy(A, B, sizeof(A))
typedef long long LL;
typedef unsigned long long uLL;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double OO = 1e20;
const double PI = acos (-1.0);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
const int maxn = 1e5+5;
LL dp[maxn], ans[maxn];
int main() {
    int t, k; scanf ("%d%d",&t,&k);
    dp[0]=1;//dp[i]有i朵花时,符合的方案数
    for (int i=1; i<=maxn; i++) {
        if (i>=k) { dp[i]= (dp[i-1]+ dp[i-k]) %MOD; }
        //dp[i-1]再吃朵红,dp[i-k]再吃k朵白
        else { dp[i]= dp[i-1] %MOD; }
    }
    for (int i=1; i<=maxn; i++) {
        ans[i]= (ans[i-1]+dp[i]) %MOD;
    }
    for (int i=0; i



你可能感兴趣的:(CodeForces,动态规划-基础)