Skip to content

Instantly share code, notes, and snippets.

@victorsenam
Last active October 16, 2016 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorsenam/cb40a1573f1775e0241520c6a82c53c0 to your computer and use it in GitHub Desktop.
Save victorsenam/cb40a1573f1775e0241520c6a82c53c0 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define debug(...) {fprintf(stderr, __VA_ARGS__);}
const int N = 5000;
ll memo[N][N];
int n, x;
int main () {
scanf("%d %d", &n, &x);
memo[n][0] = 1;
for (int y = 1; y <= x; y++)
memo[n][y] = 0;
for (int i = n-1; i >= 0; i--) {
memo[i][0] = 1;
for (int y = 1; y <= x; y++) {
memo[i][y] = memo[i+1][y-1];
for (int j = i+2; j <= n; j++)
memo[i][y] += memo[j][y];
}
}
printf("%lld\n", memo[0][x]);
}
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define debug(...) {fprintf(stderr, __VA_ARGS__);}
const int N = 5000;
ll f[N][N];
ll f[N][N];
int n, x;
int main () {
scanf("%d %d", &n, &x);
f[n][0] = g[n][0] = 1;
for (int y = 1; y <= x; y++) {
f[n][y] = 0;
g[n][y] = 0;
}
for (int i = n-1; i >= 0; i--) {
g[i][0] = f[i][0] = 1;
for (int y = 1; y <= x; y++) {
f[i][y] = f[i+1][y-1] + g[i+1][y];
g[i][y] = f[i+1][y] + g[i+1][y];
}
}
printf("%lld\n", memo[0][x]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment