-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRooks.cpp
More file actions
50 lines (47 loc) · 807 Bytes
/
Rooks.cpp
File metadata and controls
50 lines (47 loc) · 807 Bytes
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
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
ll ara[32][32];
ll ncr(ll n,ll r)
{
if(n==r || r==0)
{
ara[n][r]=1;
return 1;
}
if(r==1)
{
ara[n][r]=n;
return n;
}
if(ara[n][r]>0)
return ara[n][r];
else
{
ara[n][r]=ncr(n-1,r)+ncr(n-1,r-1);
return ara[n][r];
}
}
int main()
{
ll q;
cin>>q;
for(ll c=1; c<=q; c++)
{
ll i,j,k,l,m,n,r;
cin>>n>>k;
if(k>n)
cout<<"Case "<<c<<": "<<0<<endl;
else
{
ll ans;
ans=ncr(n,k);
for(j=n,l=1; l<=k; l++,j--)
ans*=j;
cout<<"Case "<<c<<": "<<ans<<endl;
}
}
return 0;
}