HDOJ 题目4284 A Famous Stone Collector(组合数学)
来源:互联网 发布:mysql怎么修改数据库名 编辑:程序博客网 时间:2024/05/29 05:09
A Famous Stone Collector
Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1122 Accepted Submission(s): 421
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.
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.
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.
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.
Source
Fudan Local Programming Contest 2012
Recommend
We have carefully selected several similar problems for you: 4247 4255 4252 4246 4249
题目大意:n用颜色的球,给出每种球的个数,问总共有多少种排法,石头可以不用上
#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>#define LL long long#define mod 1000000007using namespace std;LL a[110];LL c[11010][110];int dp[110][11010];void fun(){ int i,j; for(i=0;i<10010;i++) c[i][0]=1; for(i=1;i<10010;i++) for(j=1;j<=i&&j<110;j++) c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;}int main(){ LL n; int cas=0; fun(); while(scanf("%lld",&n)!=EOF) { LL i,j,k; LL sum=0; int m; // scanf("%d",&m); // printf("++++%lld\n",c[n][m]); for(i=1;i<=n;i++) { scanf("%lld",&a[i]); sum+=a[i]; } dp[0][0]=1; for(i=1;i<=n;i++) { for(j=0;j<=sum;j++) { dp[i][j]=dp[i-1][j]; for(k=1;k<=a[i];k++) { if(j-k<0) break; dp[i][j]=(dp[i][j]+dp[i-1][j-k]*c[j][k]%mod)%mod; } } } LL ans=0; for(i=1;i<=sum;i++) { ans=(ans+dp[n][i])%mod; } printf("Case %d: %lld\n",++cas,ans); }}
0 0
- HDOJ 题目4284 A Famous Stone Collector(组合数学)
- hdu 4248 A Famous Stone Collector(组合数学&DP)
- hdu 4248 A Famous Stone Collector dp+组合数学
- 【HDU 4248】组合数学 A Famous Stone Collector
- 【原创】【组合数学】HDU 4248 A Famous Stone Collector
- HDU_4248_A Famous Stone Collector(组合数学+DP)
- HDOJ 4248 A Famous Stone Collector DP
- HDU 4248 A Famous Stone Collector(组合计数)
- HDU 4248 A Famous Stone Collector(DP + 组合数)
- #HDU4248#A Famous Stone Collector(组合数)
- [ACM] hdu 4248 A Famous Stone Collector (DP+组合)
- hdu4248 A Famous Stone Collector
- hdu 4248 A Famous Stone Collector
- hdu 4248 A Famous Stone Collector
- HDU 4248 A Famous Stone Collector (dp)
- HDU 4248 A Famous Stone Collector(类多重背包+组合数)
- Famous Stone Collector HDU
- HDOJ题目1220 Cube(组合数学)
- c++ 实验探究之数组
- sicily 1259. Sum of Consecutive Primes
- 自定义泛型JAVA_116-118
- UI基础-事件处理
- 安卓 URL编码 和解码注意事项
- HDOJ 题目4284 A Famous Stone Collector(组合数学)
- ListView的优化
- 智能指针sp/wp使用
- MySQL存储引擎总结
- web开发中常用的几种统计图使用
- 配置CKFinder(Java版)
- meminfo
- UVa-511-Way to SanJose?
- 第四章 使用OpenCV探测来至运动的结构——Chapter 4:Exploring Structure from Motion Using OpenCV