标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2137 Accepted Submission(s): 1430
dp[i][j]代表前i个卡,分成j组的方法数。
当新添加一张卡时,可以选则单独放这张卡那么此时有dp[i-1][j-1]种方法。也可以选择把这张卡插入到原来的分组中,即前i-1个数分成j组后再把第i张卡片插入。有dp[i-1][j]*j种方法。
/* *********************************************** Author :guanjun Created Time :2016/6/12 20:31:58 File Name :hdu2512.cpp ************************************************ */ #include <iostream> #include <cstring> #include <cstdlib> #include <stdio.h> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <iomanip> #include <list> #include <deque> #include <stack> #define ull unsigned long long #define ll long long #define mod 1000 #define INF 0x3f3f3f3f #define maxn 10000 #define cle(a) memset(a,0,sizeof(a)) const ull inf = 1LL << 61; const double eps=1e-5; using namespace std; priority_queue<int,vector<int>,greater<int> >pq; struct Node{ int x,y; }; struct cmp{ bool operator()(Node a,Node b){ if(a.x==b.x) return a.y> b.y; return a.x>b.x; } }; bool cmp(int a,int b){ return a>b; } int dp[2010][2010]; int n; int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif //freopen("out.txt","w",stdout); int t; cin>>t; while(t--){ scanf("%d",&n); cle(dp); dp[0][0]=1; for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ dp[i][j]=dp[i-1][j-1]+dp[i-1][j]*j; dp[i][j]%=mod; } } int ans=0; for(int i=1;i<=n;i++) ans+=dp[n][i]; cout<<ans%mod<<endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/pk28/p/5578821.html