28 lines
738 B
C++
28 lines
738 B
C++
#include <bits/stdc++.h>
|
|
typedef long long ll;
|
|
using namespace std;
|
|
|
|
const int MOD = 1e9 + 7;
|
|
|
|
int main(){
|
|
int N, M; cin >> N >> M;
|
|
|
|
vector<vector<ll>> dp(N + 1, vector<ll>(2, 0));
|
|
// DP[i][j] := Number of configurations where:
|
|
// i := length of the arrangement of flowers (first i flowers placed)
|
|
// j := 0 or 1 (represents the type of the last flower placed)
|
|
dp[0][0] = dp[0][1] = 1;
|
|
for (int i = 0; i <= N; i++) {
|
|
for (int j = 0; j <= 1; j++) {
|
|
int opposite = (int)(!j);
|
|
for (int k = 1; k <= M && i + k <= N; k++) {
|
|
dp[i + k][opposite] += dp[i][j];
|
|
dp[i + k][opposite] %= MOD;
|
|
}
|
|
}
|
|
}
|
|
|
|
cout << (dp[N][0] + dp[N][1]) % MOD << endl;
|
|
|
|
return 0;
|
|
} |