Hdoj 4248 a famous Stone collector DP

Source: Internet
Author: User


DP: DP [I] [J] How many exclusive methods are there for the J-length series in heap I,

DP [I] [J] = DP [I-1] [J] (no I heap required ),

DP [I] [J] + = DP [I-1] [J-K] * C [J] [k] (using K stones heap I)


A famous Stone collector Time 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 are n colors of stones in his collection. Two stones with the same color are indistinguishable. MR. B wocould like
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 you to write a program to count the number of different possible patterns. two patterns are considered different, if and only if they have different number of stones or have different colors on at least one position.
Inputeach test case starts with a line containing an integer n indicating the kinds of stones mr. B have. Following this is a line containing N integers-the number
Available stones of each color respectively. All the input numbers will be 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 has are B, G and M, the different patterns Mr. B can form are: B; G; M; BG; BM; GM; GB; MB; MG; BGM; BMG; GBM; GMB; MBG; MGB. 
 
Sourcefudan 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])%MOD;}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;}



Hdoj 4248 a famous Stone collector DP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.