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.
Case 1: 15
Case 2: 8
Hint
分析:一類組合計數問題,設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);
}
}