The idea of recursion is as follows, I cards are divided into J-piles, then there are two cases: the first card is a bunch of cards or no self-made piles.
Then it's a bunch of dp[i-1][j-1.
Not self-made a bunch of words can be in the J heap arbitrarily pick a bunch of put, so there are dp[i-1][j]*j kind of situation
In summary, the following:
dp[i][j]=dp[i-1][j]*j+dp[i-1][j-1].
On the second kind of Stirling number, Baidu is good.
Specific code
#include <iostream>using namespacestd;intdp[2005][2005];intMain () { for(intI=1; i<= -; i++) {dp[1][i]=0; dp[i][0]=dp[i][1]=1;//use dp[i][0] to store the total possible number of I card storage } for(intI=2; i<= -; i++) for(intj=2; j<= -; j + +) {Dp[i][j]=dp[i-1][j]*j+dp[i-1][j-1]; DP[I][J]%= +; if(dp[i][j]!=0) {dp[i][0]+=Dp[i][j]; dp[i][0]%= +; } } intn,t; CIN>>T; while(t--) {cin>>O; cout<<dp[n][0]<<Endl; }}
Hdu 25,121 cartoon Big Adventure (second class sterling number)