hdu A Famous Stone Collector
A Famous Stone Collector
Problem Description
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.
available stones of each color respectively. All the input numbers will be nonnegative and no more than 100.
which is a prime number.
给定n种颜色的石头,每种颜色有si颗,同种颜色的石头不区分。问能构成多少种不同的石头序列(不同的序列是指:1.石头数不同;2.石头数相同,至少一个位置的石头颜色不同)
Ways[i]表示选i个石头的不同种类
其中C[ n ][ m ]表示组合数。
AC代码:
#include <stdio.h>
#include <string.h>
#define mod 1000000007
long long c[100005][150];
long long ways[100005];
long long a[100005];
void init( )
{
c[0][0]=1;
for( int i=1;i<=10000;i++)
{
c[i][0]=1;
for( int j=1;j<=100&&j<=i;j++)
{
c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
}
}
}
int main( )
{
int i,j,u;
int n,total;
int m=1;
init( );
while(scanf("%d",&n)!=EOF)
{
for( i=0;i<n;i++)
{
scanf("%lld",&a[i]);
}
memset(ways,0,sizeof(ways));
total=0;
ways[0]=1;
for( i=0;i<n;i++)
{
total+=a[i];
for( j=total;j>=0;j--)
{
for(u=1;u<=a[i];u++)
{
ways[j]+=ways[j-u]*c[j][u];
ways[j]%=mod;
}
}
}
long long ans=0;
for( i=1;i<=total;i++)
{
ans=(ans+ways[i])%mod;
}
printf("Case %lld: %d\n",m++,ans);
}
return 0;
}