Skip to content

Instantly share code, notes, and snippets.

@mccraveiro
Created June 14, 2012 22:05
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 mccraveiro/2933259 to your computer and use it in GitHub Desktop.
Save mccraveiro/2933259 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int pd[13][99];
int permut(n, k) {
if (pd[n][k] != -1)
return pd[n][k];
int i;
pd[n][k] = 0;
for (i = 0; i < n; i++){
if(k - i < 0) break;
pd[n][k] += permut(n - 1, k - i);
}
return pd[n][k];
}
int main(){
int d, i, j, n, k;
for (k = 0; k < 99; k++)
pd[1][k] = 0;
pd[1][0] = 1;
for (n = 2; n < 13; n++) {
for (k = 0; k < 99; k++) {
pd[n][k] = -1;
}
}
scanf("%d", &d);
for (i = 0; i < d; i++){
scanf("%d %d", &n, &k);
printf("%d\n", permut(n, k));
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment