Created
June 14, 2012 22:05
-
-
Save mccraveiro/2933259 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 <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