Last active
October 16, 2016 04:28
-
-
Save victorsenam/cb40a1573f1775e0241520c6a82c53c0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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; | |
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]); | |
} |
This file contains hidden or 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; | |
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