Created
September 5, 2023 01:14
-
-
Save estelabn/0124a35557ba038ad3a6ae5db6272458 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
#define int long long | |
const int MOD = 1000000007; | |
signed main(){ | |
ios_base::sync_with_stdio(false); | |
cin.tie(NULL); | |
int g, m; cin >> g >> m; | |
if(m == 1){ | |
vector<int> dp(g+5, (int)0); | |
dp[0] = (int)1; | |
for(int i = 1; i<=g; i++){ | |
for(int o = 0; o<(int)200; o++){ | |
int a = o * (o+1) * (2*o + 1); | |
a /= 6; | |
if(a > i) continue; | |
dp[i] += dp[i-a]; | |
dp[i] %= MOD; | |
} | |
} | |
cout << dp[g] << "\n"; | |
} | |
if(m == 2){ | |
vector<pair<int,int>> dp(g+5, {0,0}); | |
dp[0] = {0,1}; | |
for(int i= (int) 1; i<=g; i++){ | |
int menor = 0, qnt = 0; | |
for(int j = 1; j<200; j++){ | |
int a = (j) * (j+1) * (2*j+1); | |
a/=6; | |
if(a > i) continue; | |
auto [aa,bb] = dp[i-a]; | |
if(menor == 0){menor = aa + 1; qnt = bb; qnt %= MOD;} | |
else if (menor == aa + 1){qnt += bb; qnt %=MOD;} | |
else if(aa + 1 < menor){menor = aa + 1; qnt = bb;qnt %= MOD;} | |
} | |
dp[i] = {menor, qnt}; | |
} | |
cout << dp[g].second << "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment