题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3185
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
题意:赛马结果,求有多少种
思路:递推关系:dp[i][j]=j*(dp[i-1][j](第i个马和前面的马搭伙到达)+dp[i-1][j-1](第i个马单独算一次))
代码:
#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<string> #include<vector> #include<stack> #include<bitset> #include<cstdlib> #include<cmath> #include<set> #include<list> #include<deque> #include<map> #include<queue> using namespace std; typedef long long ll; const double PI = acos(-1.0); const double eps = 1e-6; const int MAXN =1e3+10; int ans[MAXN]; int h[MAXN][MAXN]={0}; int T; const int MOD =10056; int horse(){ for(int i=1;i<MAXN;i++){ h[i][1]=1; for(int j=2;j<=i;j++){ h[i][j]=(h[i-1][j-1]*j%MOD+h[i-1][j]*j%MOD)%MOD; } for(int j=1;j<=i;j++){ ans[i]=(ans[i]+h[i][j])%MOD; } } return 0; } int main(void){ horse(); scanf("%d",&T); //freopen("out.txt","wa",stdout); for(int i=0;i<T;i++){ int a=0; scanf("%d",&a); printf("Case %d: %d\n",i+1,ans[a]); } return 0; }
原文地址:https://www.cnblogs.com/caomingpei/p/8352320.html
时间: 2024-10-09 22:36:21