两人赛马,最终名次有3种可能
求n人赛马时最终名次的可能性的个数
#include<iostream> #include<cstring> #include<algorithm> #include<set> using namespace std; #define mod 10056 int c[1002][1002],n,f[1002]; void init_c(){ int i,j; c[1][1]=1; for(i=0;i<=1000;i++) c[i][0]=1; for(i=2;i<=1000;i++) for(j=1;j<=i;j++) c[i][j]=(c[i-1][j]+c[i-1][j-1]),c[i][j]%=mod; } int F(int x){ if(~f[x]) return f[x] ; int i, s=0; for(i=1;i<=x;i++) s+=c[x][i]*F(x-i),s%=mod; return f[x]=s; } signed main() { init_c(); int cas=0; int tes;cin>>tes; memset(f,-1,sizeof f);f[0]=f[1]=1,f[2]=3; while(tes--){ int n;cin>>n; printf("Case %d: %d\n",++cas,F(n)); } }
标签:tes,名次,int,uva12034,Race,include,1002 From: https://www.cnblogs.com/towboa/p/17300158.html