Last active
August 18, 2021 20:47
-
-
Save LucaDantas/b6721e90f4ac9ac60a4c7fd545e28303 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 <cstdio> | |
const int maxn = 1e5+10; // perceba que com esses limites a resposta pode ser muito maior que o limite de um inteiro | |
int dp[maxn], n, k; | |
bool mark[maxn]; | |
int solve(int x) { | |
if(x == n) return 1; | |
if(x > n) return 0; // possibilidade 1 de lidar com os casos de base | |
if(mark[x] == 1) return dp[x]; | |
mark[x] = 1; | |
for(int i = 1; i <= k; i++) { | |
if(i + x > n) break; // possibilidade 2 de lidar com os casos de base | |
dp[x] += solve(x+i); | |
} | |
return dp[x]; | |
} | |
int main() { | |
scanf("%d %d", &n, &k); | |
printf("%d\n", solve(1)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment