zoukankan      html  css  js  c++  java
  • HDOJ 4248 A Famous Stone Collector DP


    DP: dp[i][j]前i堆放j序列长度有多少行法,

    dp[i][j]=dp[i-1][j] (不用第i堆), 

    dp[i][j]+=dp[i-1][j-k]*C[j][k] (用第i堆的k个石头)


    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 Description
    Mr. 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 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 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.
     

    Input
    Each 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 of 
    available stones of each color respectively. All the input numbers will be nonnegative and no more than 100.
     

    Output
    For 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
    3 1 1 1 2 1 2
     

    Sample Output
    Case 1: 15 Case 2: 8
    Hint
    In 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.
     

    Source
     




    #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
    ",cas++,ans%MOD);
        }
        return 0;
    }
    



    版权声明:来自: 代码代码猿猿AC路 http://blog.csdn.net/ck_boss

  • 相关阅读:
    Programming WCF Services作者序
    《软件设计精要与模式》书评
    Programming WCF Services翻译笔记(九)
    检验团队是否敏捷的四个标准
    Programming WCF Services翻译笔记(八)
    Oracle BIEE (Business Intelligence) 11g 11.1.1.6.0 学习(3)创建一个简单的分析
    oracle express 11g 创建表空间
    vmware8安装win2008 r2后找不到网卡驱动的解决办法
    javascript:巧用eval函数组装表单输入项为json对象
    javascript:二叉搜索树 实现
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/4876861.html
Copyright © 2011-2022 走看看