forked from mohitsh/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpermut1.cpp
36 lines (36 loc) · 1.35 KB
/
permut1.cpp
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
// 2008-07-10
#include <cstdio>
#include <algorithm>
using namespace std;
static int answers[13][99]=
{
{0},
{1},
{1},
{1, 2},
{1, 3, 5, 6},
{1, 4, 9, 15, 20, 22},
{1, 5, 14, 29, 49, 71, 90, 101},
{1, 6, 20, 49, 98, 169, 259, 359, 455, 531, 573},
{1, 7, 27, 76, 174, 343, 602, 961, 1415, 1940, 2493, 3017, 3450, 3736, 3836},
{1, 8, 35, 111, 285, 628, 1230, 2191, 3606, 5545, 8031, 11021, 14395, 17957, 21450, 24584, 27073, 28675, 29228},
{1, 9, 44, 155, 440, 1068, 2298, 4489, 8095, 13640, 21670, 32683, 47043, 64889, 86054, 110010, 135853, 162337, 187959, 211089, 230131, 243694, 250749},
{1, 10, 54, 209, 649, 1717, 4015, 8504, 16599, 30239, 51909, 84591, 131625, 196470, 282369, 391939, 526724, 686763, 870233, 1073227, 1289718, 1511742, 1729808, 1933514, 2112319, 2256396, 2357475, 2409581, 2357475, 2256396, 2112319, 1933514, 1729808, 1511742},
{1, 11, 65, 274, 923, 2640, 6655, 15159, 31758, 61997, 113906, 198497, 330121, 526581, 808896, 1200626, 1726701, 2411747, 3277965, 4342688, 5615807, 7097310, 8775209, 10624132, 12604826, 14664752, 16739858, 18757500, 20640357, 22311069, 23697232, 24736324, 25380120, 25598186}
};
int main()
{
int d,i,n,k;
scanf("%d",&d);
for (i=0; i<d; i++)
{
scanf("%d %d",&n,&k);
if (k<=n*(n-1)/4)
printf("%d\n",answers[n][k]);
else if (k<=n*(n-1)/2)
printf("%d\n",answers[n][n*(n-1)/2-k]);
else
printf("0\n");
}
return 0;
}