- #include <bits/stdc++.h>
- using namespace std;
- #define MOD 1000000007
- #define N 1005
- #define ll long long unsigned
- ll fac[N];
- ll dp[N][N];
- int pre(){
- fac[0] = 1;
- for(int i = 1; i <N; i++) fac[i]= (fac[i-1]*i)%MOD;
- memset(dp, -1, sizeof(dp));
- }
- ll ncr(int n, int k){
- if(k==1) return n;
- if(n==k) return 1;
- if(dp[n][k]!=-1) return dp[n][k];
- return dp[n][k]= (ncr(n-1,k-1)+ncr(n-1,k))%MOD;
- }
- int main(){
- pre();
- int ts;
- scanf("%d", &ts);
- for(int p =1;p <= ts; p++){
- int n, m, k;
- scanf("%d%d%d", &n, &m, &k);
- ll ans1 = ncr(m, k);
- ll ans2 = fac[n-k];
- for(int i = 1; i <= m-k; i++){
- if(i%2) ans2-= (ncr(m-k, i)*fac[n-k-i])%MOD;
- else ans2+= (ncr(m-k, i)*fac[n-k-i])%MOD;
- ans2 = (ans2+MOD)%MOD;
- }
- printf("Case %d: %llu\n",p, (ans1*ans2)%MOD);
- }
- return 0;
- }
Saturday 29 July 2017
Lightoj 1095 - Arrange the Numbers
Subscribe to:
Post Comments (Atom)
Most Featured Post
Lightoj 1159 - Batman
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
-
Problem link: Problem Analysis: It is actually a basic Bisection problem , as we can see here we can not actually find a formula fo...
-
http://lightoj.com/volume_showproblem.php?problem=1382 Problem analysis: This is a rare problem i wrote about so far. After much strugg...
No comments:
Post a Comment