码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 4248

时间:2014-12-16 07:40:55      阅读:321      评论:0      收藏:0      [点我收藏+]

标签:des   blog   http   ar   io   color   os   使用   sp   

A Famous Stone Collector

Time Limit: 30000/15000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 876    Accepted Submission(s): 329


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
 

 

Recommend
 

dp[i][j] 表示前i堆石子构成长度为j的串的方案数;

状态转移方程是:k为i堆使用的数量

dp[i][j] = (dp[i][j] + dp[i-1][j-k] * C[j][k]%M)%M;
自己写挫了,上一大神代码。
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define M 1000000007
long long dp[110][10010];
long long C[11000][110];
void cc()
{
    int i,j;
    C[0][0]=1;
    for(i=1;i<10010;i++)
        for(j=0;j<=100;j++)
            if(j == 0) C[i][j] = C[i-1][j];
            else C[i][j] = (C[i-1][j]+C[i-1][j-1])%M;
            //C[i][j]=(j==0) ? C[i-1][j] : ();
}
int main()
{
    cc();
    int n;
    int cas = 1;
    while(cin >> n)
    {
        memset(dp,0,sizeof(dp));
        dp[0][0] = 1;
        int sum = 0;
        for(int i = 1;i <= n;i++)
        {
            int t;
            cin >> t;
            sum += t;
            for(int k = 0;k <= t;k++)
                for(int j = k;j <= sum;j++)
                    dp[i][j] = (dp[i][j] + dp[i-1][j-k] * C[j][k]%M)%M;
           
        }
        long long re = 0;
        for(int i = 1;i <= sum;i++) re = (re + dp[n][i])%M;
        cout << "Case " << cas++<< ": " << re << "\n";
    }
    return 0;
}

  

 

hdu 4248

标签:des   blog   http   ar   io   color   os   使用   sp   

原文地址:http://www.cnblogs.com/a972290869/p/4166265.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!