HDU 4248 A Famous Stone Collector(组合计数)
来源:互联网 发布:淘宝的电脑主机能买吗 编辑:程序博客网 时间:2024/05/17 03:42
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: 8Hint
分析:一类组合计数问题,设DP[i][j]:前i个组成长度为j的方案数
那么对于第i种颜色,只需考虑转移到此状态的方案数。
dp[i][j]=dp[i-1][j]+dp[i][j-k]*C(j,k)
#include<cstdio>#include<cstring>#include<algorithm>#include<vector>#include<string>#include<iostream>#include<queue>#include<cmath>#include<map>#include<stack>#include<set>using namespace std;#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define CLEAR( a , x ) memset ( a , x , sizeof a )const int INF=0x3f3f3f3f;typedef long long LL;const int maxn=1010;const int mod=1e9+7;LL C[110*110][110];int A[110];LL dp[110][10100];void init(){ C[1][0]=C[1][1]=C[0][0]=1; for(int i=2;i<=10000;i++) { C[i][0]=1; for(int j=1;j<=100;j++) { if(j==i) C[i][i]=1; else C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod; } }}int main(){ int n;init(); int cas=1; while(~scanf("%d",&n)) { CLEAR(dp,0); int S=0; REPF(i,1,n) { scanf("%d",&A[i]); S+=A[i]; } dp[0][0]=1; for(int i=1;i<=n;i++) { for(int j=0;j<=S;j++) { dp[i][j]=dp[i-1][j]; for(int k=1;k<=A[i];k++) { if(j-k<0) continue; dp[i][j]=(dp[i][j]+dp[i-1][j-k]*C[j][k]%mod)%mod; } } } LL res=0; for(int i=1;i<=S;i++) res=(res+dp[n][i])%mod; printf("Case %d: %lld\n",cas++,res); }}
0 0
- HDU 4248 A Famous Stone Collector(组合计数)
- HDU 4248 A Famous Stone Collector(DP + 组合数)
- hdu 4248 A Famous Stone Collector(组合数学&DP)
- hdu 4248 A Famous Stone Collector dp+组合数学
- [ACM] 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
- hdu 4248 A Famous Stone Collector
- HDU 4248 A Famous Stone Collector (dp)
- HDU 4248 A Famous Stone Collector(类多重背包+组合数)
- HDOJ 题目4284 A Famous Stone Collector(组合数学)
- #HDU4248#A Famous Stone Collector(组合数)
- Famous Stone Collector HDU
- HDOJ 4248 A Famous Stone Collector DP
- hdu4248 A Famous Stone Collector
- hdu 4248 A Famous Stone Collector【DP】【Fudan Local Programming Contest 2012 D】
- HDU_4248_A Famous Stone Collector(组合数学+DP)
- 学习小结20150923--URL及媒体
- Light oj 1122 Digit Count(简单dp)
- 使用SQLiteOpenHelper插入数据到数据库并读取数据库中的内容
- level-list根据setimagelevel和setlevel方法中给的int显示图片;和selector类似
- 数据库索引的作用和优点缺点
- HDU 4248 A Famous Stone Collector(组合计数)
- xcode自动生成project-swift.h出错
- OCP-V13-306
- Spring MVC之@RequestBody, @ResponseBody 详解
- Mac OS
- VMware安装Linux ubuntu虚拟机
- 面向对象——内部类
- 150923
- LeetCode Contains Duplicate