标签:blog io os for sp div c log amp
简单错排
#include <iostream> #include <cstdio> #include <algorithm> #define LL __int64 using namespace std; LL Cnk[25][25]; LL Dn[25]; void initial(){ for(LL i=1;i<25;i++){ Cnk[i][0]=1; for(LL j=1;j<=i;j++){ if(j==1) Cnk[i][j]=i; else Cnk[i][j]=Cnk[i][j-1]*(i-j+1)/j; } } Dn[0]=1; Dn[1]=0; Dn[2]=1; for(LL i=3;i<25;i++) Dn[i]=(i-1)*(Dn[i-2]+Dn[i-1]); } int main(){ initial(); int T,n,m; scanf("%d",&T); while(T--){ scanf("%d%d",&n,&m); LL ans=Cnk[n][n-m]*Dn[m]; printf("%I64d\n",ans); } return 0; }
标签:blog io os for sp div c log amp
原文地址:http://www.cnblogs.com/jie-dcai/p/4003070.html