DP:DP[I][J] before I stacking j sequence length How many lines of law,
DP[I][J]=DP[I-1][J] (without the first heap),
Dp[i][j]+=dp[i-1][j-k]*c[j][k] (K-stones with Heap i)
A Famous Stone CollectorTime
limit:30000/15000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 845 Accepted Submission (s): 322
Problem descriptionmr. B loves to play with colorful stones. There is n colors of stones in his collection. The stones with the same color is indistinguishable. Mr. B would like to
Select some stones and arrange them in line to form a beautiful pattern. After several arrangements he finds it very hard for him to enumerate all the patterns. So he asks the number of different possible patterns from the write a program to count. Patterns is considered different, if and only if they has different number of stones or has different colors on least one position.
Inputeach test case starts with a line containing an integer n indicating the kinds of stones Mr. B has. Following this was a line containing n integers-the number of
Available stones of each color respectively. All the input numbers is nonnegative and no more than 100.
Outputfor Each test case, display a single line containing the case number and the number of different patterns Mr. B can Make with these stones, modulo 1,000,000,007,
Which is a prime number.
Sample Input
31 1 121 2
Sample Output
Case 1:15case 2:8Hintin the first case, suppose the colors of the Stones Mr. B have is B, G and M, the Differen T patterns Mr. B can form are:b; G M BG; BM; GM; GB; MB; MG; BGM; BMG; GBM; GMB; MBG; MGB.
Source
Field=problem&key=fudan+local+programming+contest+2012&source=1&searchmode=source "style=" Color:rgb (26,92,200); Text-decoration:none ">fudan Local programming Contest 2012
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm>using namespace Std;typedef Long Long int ll;const LL MOD = 1000000007LL; LL c[11000][210];void GetC () {for (int i=0;i<11000;i++) c[i][0]=c[i][i]=1; for (int i=2;i<11000;i++) for (int j=1;j<i&&j<=200;j++) c[i][j]= (c[i-1][j]+c[i-1][j-1])%M OD;} LL dp[110][11000];int N,a[110];int Main () {GetC (); int Cas=1; while (scanf ("%d", &n)!=eof) {for (int i=1;i<=n;i++) scanf ("%d", a+i); Memset (Dp,0,sizeof (DP)); int len=0; Dp[0][0]=1; for (int i=1;i<=n;i++) {len+=a[i]; for (int j=0;j<=len;j++) {dp[i][j]= (dp[i][j]+dp[i-1][j])%mod; for (int k=1;k<=a[i]&&j-k>=0;k++) {dp[i][j]= (Dp[i][j]+dp[i-1][j-k]*c[j][k] )%mod; }}} LL ans=0; for (int i=1;i<=len;i++) ans= (ans+dp[n][i])%mod; printf ("Case%d:%lld\n", cas++,ans%mod); } return 0;}
Copyright statement: From: Code Code APE Ape AC Road Http://blog.csdn.net/ck_boss
Hdoj 4248 A Famous Stone Collector DP