题目链接:http://lightoj.com/volume_showproblem.php?problem=1005
#include <cstdio> #include <cstring> #include <iostream> #include <cmath> #include <algorithm> #include <queue> #include <vector> using namespace std; const int maxe = 50000; const int maxn = 50; const int INF = 0x3f3f3f; float dp[maxn]; long long C[maxn][maxn]; long long A[maxn][maxn]; int main() { //freopen("E:\acm\input.txt","r",stdin); int T; cin>>T; for(int i=1;i<=30;i++) C[i][0] = 1; A[1][1] = 1; for(int i=2;i<=30;i++) A[i][i] = A[i-1][i-1]*i; for(int n=1;n<=30;n++) for(int k=1;k<=n;k++){ C[n][k] = C[n][k-1] * (n-k+1)/k; A[n][k] = C[n][k]*A[k][k]; } for(int t=1;t<=T;t++){ int n,k; cin>>n>>k; printf("Case %d: ",t); dp[0] = 1; if(k > n ) printf("0 "); else if(k == 0 ) printf("1 "); else{ cout<<A[n][k]*C[n][k]<<endl; } } }