let's start Code

1005 - Rooks

1005 - Rooks

Topic: combinatorics + Binomial Coefficient



#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll nCr(int n, int k)
{
ll ans[n+1][k+1];
int i,j;
for(int i = 0; i <= n; i++){
for(int j = 0; j <= min(i,k); j++){
if(j == 0 || j == i)
ans[i][j] = 1;
else{
ans[i][j] = ans[i-1][j-1] + ans[i-1][j];
}
}
}
return ans[n][k];
}
int main()
{
int T;
scanf("%d", &T);
for(int cs = 1; cs <= T; cs++)
{
ll n,k;
cin >> n >> k;
ll res = nCr(n,k);
for(int i =0; i < k; i++){
res *= n;
n--;
}
printf("Case %d: ",cs);
cout << res << endl;
}
return 0;
}
view raw rook.cpp hosted with ❤ by GitHub
Share:

Related Posts:

No comments:

Post a Comment

About

let's start CODE

Popular Posts