feat: alternative AC solution and TLE solution implemented, also wrote the tutorial for the problem and improved its description

This commit is contained in:
2025-11-12 10:56:03 -03:00
parent 063c8815c7
commit cf745f4cb4
12 changed files with 190 additions and 18 deletions

View File

@@ -0,0 +1,45 @@
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int N, M;
const int MOD = 1e9 + 7;
ll memo[10001][1001][2];
ll flowers(int last, int count = 1, int size = 1) {
if (size == N) return 1;
/*
if sequences ends with X we have to cases:
if count(X) < M we can continue the sequence by appending another X in its end
we can also start and entirely new sequence starting with Y.
*/
if (memo[size][count][last] == 0) {
if (last == 0) {
if (count < M)
memo[size][count][0] += flowers(0, count + 1, size + 1);
memo[size][count][0] += flowers(1, 1, size + 1);
} else {
if (count < M)
memo[size][count][1] += flowers(1, count + 1, size + 1);
memo[size][count][1] += flowers(0, 1, size + 1);
}
}
return memo[size][count][last] %= MOD;
}
int main(){
cin >> N >> M;
for (int i = 0; i <= 10000; i++) {
for (int j = 0; j <= 1000; j++) {
memo[i][j][0] = memo[i][j][1] = 0;
}
}
cout << (flowers(0) + flowers(1)) % MOD << endl;
return 0;
}