feat(DP): new dp problems formated
This commit is contained in:
25
flowers/src/ac.cpp
Normal file
25
flowers/src/ac.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <bits/stdc++.h>
|
||||
typedef long long ll;
|
||||
using namespace std;
|
||||
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << dp[N][0] + dp[N][1] << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user