HDOJ 4248 A Famous Stone Collector DP
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
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.
3
1 1 1
2
1 2
Case 1: 15
Case 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.
#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的更多相关文章
- [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 ...
- HDU 4248 A Famous Stone Collector 组合数学dp ****
A Famous Stone Collector Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- hdu 4248 A Famous Stone Collector
首先发现一个很头痛的问题,下面是2个求排列组合的代码 memset(C,,sizeof(C)); ;i<;i++) { C[i][]=; ;j<=;j++) C[i][j]=(C[i-][ ...
- HDOJ(HDU).2602 Bone Collector (DP 01背包)
HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio&g ...
- HDOJ(HDU).1284 钱币兑换问题 (DP 完全背包)
HDOJ(HDU).1284 钱币兑换问题 (DP 完全背包) 题意分析 裸的完全背包问题 代码总览 #include <iostream> #include <cstdio> ...
- HDOJ 1257 最少拦截系统 【DP】
HDOJ 1257 最少拦截系统 [DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDOJ 4249 A Famous Equation DP
DP: DP[len][k][i][j] 再第len位,第一个数len位为i,第二个数len位为j,和的第len位为k 每一位能够从后面一位转移过来,能够进位也能够不进位 A Famous Equat ...
- 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这一段的价值. # ...
- [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 ...
随机推荐
- POJ 1276 Cash Machine(多重背包)
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24132 Accepted: 8446 Descrip ...
- boost事件处理
尽管这个库的名字乍一看好象有点误导,但实际上并不是如此. Boost.Signals 所实现的模式被命名为 '信号至插槽' (signal to slot).它基于下面概念:当相应的信号被发出时.相关 ...
- hibernate 大对象类型hibernate制图
基础知识: 在 Java 在, java.lang.String 它可以用来表示长串(超过长度 255), 字节数组 byte[] 可用于存放图片或文件的二进制数据. 此外, 在 JDBC API 中 ...
- Shine we together: A innovative dating site using 2012 Nobel Laureate Roth's algorithm
Abstract Our dating site introduced scoring and its related functionalities innovatively, conforming ...
- windows phone (27) 基础Button
原文:windows phone (27) 基础Button Button 在wp7中因其灵活性经常会用到,我们在ContentPanel中直接添加Button,button默认状态下是把整个grid ...
- 【oracle案件】ORA-19502,ORA-27072
1.1.1. ORA-19502,ORA-27072 日期:2014-05-12 00:12 环境:试验机 [错误号] $ oerr ora 19502 19502, 00000, "wri ...
- 【Android 应用开发】 FastJson 使用具体解释
博客地址 :http://blog.csdn.net/shulianghan/article/details/41011605 fastjson 源代码地址 : -- GitHub : https:/ ...
- leetcode dfs Validate Binary Search Tree
Validate Binary Search Tree Total Accepted: 23828 Total Submissions: 91943My Submissions Given a bin ...
- ubuntu12.04硬盘安装
ubuntu12.04发布了 , 安装又是一个话题.安装系统有很多方法,比如livecd,和u盘,但这些都需借用外部设备,所以硬盘安装是最好不过的方法了.u盘,cd安装都非常的简 单,对于那些讨厌用光 ...
- 重新想象 Windows 8 Store Apps (18) - 绘图: Shape, Path, Stroke, Brush
原文:重新想象 Windows 8 Store Apps (18) - 绘图: Shape, Path, Stroke, Brush [源码下载] 重新想象 Windows 8 Store Apps ...