Skip to content

Instantly share code, notes, and snippets.

@mccraveiro mccraveiro/permut1.c
Created Jun 14, 2012

Embed
What would you like to do?
#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
You can’t perform that action at this time.