Skip to content

Instantly share code, notes, and snippets.

@LucaDantas
Last active August 18, 2021 20:46
Show Gist options
  • Save LucaDantas/a04c263bfacb238433765eda175eb222 to your computer and use it in GitHub Desktop.
Save LucaDantas/a04c263bfacb238433765eda175eb222 to your computer and use it in GitHub Desktop.
#include <cstdio>
const int maxn = 510;
int dp[maxn][maxn], n;
bool mark[maxn][maxn];
int solve(int pos, int last) {
if(pos == n) return 1;
if(mark[pos][last]) return dp[pos][last];
for(int i = pos+last+1; i <= n; i++) // já lidamos com as restrições dentro do for para simplificar a implementação
dp[pos][last] += solve(i, i-pos);
mark[pos][last] = 1;
return dp[pos][last];
}
int main() {
scanf("%d", &n);
printf("%d\n", solve(1, 0));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment