-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1010.c
52 lines (44 loc) · 821 Bytes
/
1010.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
int combi[1000][1000];
/*
int Combi(int M, int N)
{
if(M==N || N == 0)
return 1;
else if(combi[M][N])
return combi[M][N];
else
return combi[M][N] = (combi[M-1][N-1] = Combi(M-1, N-1)) + (combi[M-1][N] = Combi(M-1, N));
}
*/
int hockey(int M, int N)
{
printf("M: %d, N: %d\n", M, N);
if(M == N)
return combi[M][N] = 1;
else if(N == 0)
return (combi[M][N] = 1) + hockey(M-1, N);
else if(combi[M][N])
return combi[M][N] + hockey(M-1, N);
else
return (combi[M][N] = hockey(M-1, N-1)) + hockey(M-1, N);
}
int Combi(int M, int N)
{
if(N==0)
return combi[M][N] = 1;
else
return combi[M][N] = hockey(M-1, N-1);
}
int main(void)
{
int i, T;
int N, M;
scanf("%d", &T);
for(i=0; i<T; i++)
{
scanf("%d %d", &N, &M);
printf("%d\n", Combi(M, N));
}
return 0;
}