DP: dp[i][j]前i堆放j序列长度有多少行法,

dp[i][j]=dp[i-1][j] (不用第i堆),

dp[i][j]+=dp[i-1][j-k]*C[j][k] (用第i堆的k个石头)

A Famous Stone Collector

Time Limit: 30000/15000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 845    Accepted Submission(s): 322

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
 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; typedef long long int LL; const LL MOD = 1000000007LL; LL C[11000][210];
void getC()
{
for(int i=0;i<11000;i++) C[i][0]=C[i][i]=1;
for(int i=2;i<11000;i++)
for(int j=1;j<i&&j<=200;j++)
C[i][j]=(C[i-1][j]+C[i-1][j-1])%MOD;
} LL dp[110][11000];
int n,a[110]; int main()
{
getC();
int cas=1;
while(scanf("%d",&n)!=EOF)
{
for(int i=1;i<=n;i++)
scanf("%d",a+i);
memset(dp,0,sizeof(dp));
int len=0;
dp[0][0]=1;
for(int i=1;i<=n;i++)
{
len+=a[i];
for(int j=0;j<=len;j++)
{
dp[i][j]=(dp[i][j]+dp[i-1][j])%MOD;
for(int k=1;k<=a[i]&&j-k>=0;k++)
{
dp[i][j]=(dp[i][j]+dp[i-1][j-k]*C[j][k])%MOD;
}
}
}
LL ans=0;
for(int i=1;i<=len;i++)
ans=(ans+dp[n][i])%MOD;
printf("Case %d: %lld\n",cas++,ans%MOD);
}
return 0;
}

版权声明:来自: 代码代码猿猿AC路 http://blog.csdn.net/ck_boss

HDOJ 4248 A Famous Stone Collector DP的更多相关文章

  1. [ACM] hdu 4248 A Famous Stone Collector (DP+组合)

    A Famous Stone Collector Problem Description Mr. B loves to play with colorful stones. There are n c ...

  2. HDU 4248 A Famous Stone Collector 组合数学dp ****

    A Famous Stone Collector Time Limit: 30000/15000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  3. hdu 4248 A Famous Stone Collector

    首先发现一个很头痛的问题,下面是2个求排列组合的代码 memset(C,,sizeof(C)); ;i<;i++) { C[i][]=; ;j<=;j++) C[i][j]=(C[i-][ ...

  4. HDOJ(HDU).2602 Bone Collector (DP 01背包)

    HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio&g ...

  5. HDOJ(HDU).1284 钱币兑换问题 (DP 完全背包)

    HDOJ(HDU).1284 钱币兑换问题 (DP 完全背包) 题意分析 裸的完全背包问题 代码总览 #include <iostream> #include <cstdio> ...

  6. HDOJ 1257 最少拦截系统 【DP】

    HDOJ 1257 最少拦截系统 [DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...

  7. HDOJ 4249 A Famous Equation DP

    DP: DP[len][k][i][j] 再第len位,第一个数len位为i,第二个数len位为j,和的第len位为k 每一位能够从后面一位转移过来,能够进位也能够不进位 A Famous Equat ...

  8. hdoj 2829 Lawrence 四边形不等式优化dp

    dp[i][j]表示前i个,炸j条路,并且最后一个炸在i的后面时,一到i这一段的最小价值. dp[i][j]=min(dp[i][k]+w[k+1][i]) w[i][j]表示i到j这一段的价值. # ...

  9. [HDOJ - 5282] Senior's String 【DP】

    题目链接:BZOJ - 5282 题目分析 LCS 就是用经典的 O(n^2) DP 解决,f[i][j] 表示 x 串前 i 个字符与 y 串前 j 个字符的 LCS 长度. f[i][j] = m ...

随机推荐

  1. J2SE基础:4.面向对象的特性一

    面向对象的特性 封装 继承多态 封装: 定义: 通过对象的封装,实现了模块化和信息隐藏. 通过对类的成员施以一定的訪问权限,实现了类中成员 的信息隐藏 注意点: 对象自已该做的一些事情与方法不能交与其 ...

  2. android studio下gradle与Git错误解决方法

    Error: Gradle: Execution failed for task ':mytask' > A problem occurred starting process 'command ...

  3. 通过action 跨进程启动activity

    在一些场景中我们需要从一个进程启动另外的一个应用的activity,这有什么好办法? 这里介绍一种方法,通过自定义 action 通过filter来启动. 如果你需要启动一个你自己写的另一个app的a ...

  4. oracle12c(oracle12.1.0.1.0)安装指南--实测OEL5.9(RH5)

    [root@oel ora12c]# uname -a Linux oel 2.6.39-300.26.1.el5uek #1 SMP Thu Jan 3 18:31:38 PST 2013 x86_ ...

  5. C++写一个简单的解析器(分析C语言)

    该方案实现了一个分析C语言的词法分析+解析. 注意: 1.简单语法,部分秕.它可以在本文法的基础上进行扩展,此过程使用自上而下LL(1)语法. 2.自己主动能达到求First 集和 Follow 集. ...

  6. 优化移动设备上SharePoint 2013网站

    优化移动设备上SharePoint 2013网站 本文由SPFarmer翻译自Waldek Mastykarz的文章 移动市场在持续的增长.在不远的将来,使用移动设备浏览站点将会超过电脑.为了保证用户 ...

  7. 重新想象 Windows 8 Store Apps (4) - 控件之提示控件: ProgressRing; 范围控件: ProgressBar, Slider

    原文:重新想象 Windows 8 Store Apps (4) - 控件之提示控件: ProgressRing; 范围控件: ProgressBar, Slider [源码下载] 重新想象 Wind ...

  8. 获取LayoutInflater的三种方式

    1.LayoutInflater.from(mContext); 2.Activity类的getLayoutInflater 3.(LayoutInflater)mContext.getSystemS ...

  9. 【安卓笔记】高速的发展设置界面-----PreferenceActivity

    通常app都会有一个设置界面,例如以下: 通常做法是自定义布局,然后在代码里面加入响应函数,并将结果保存到Sharedpreferences中. android给我们提供了PreferenceActi ...

  10. WPF中的三维空间(1)

    原文:WPF中的三维空间(1) WPF中可以创建三维几何图形,支持3D对象的应用,支持从3D Max等软件将3D文件obj导入设计中,但是目前还不支持将材质同时导入,这样需要在WPF中对3D对象重新设 ...