HDU 4248 A Famous Stone Collector 组合数学dp ****
A Famous Stone Collector
Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 793 Accepted Submission(s): 292
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.
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.
转台转移方程:
dp[ i ][ j ] = dp[ i-1 ][ j ]; //未放入第i种颜色的石头
for k := 1 ~ min( j , s[ i ] ) //放入k个第i种颜色的石头
dp[ i ][ j ] += dp[ i-1 ][ j - k ] * C[ j ][ k ]; //!!!
其中C[ n ][ m ]表示组合数。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef __int64 LL;
const LL mod=; LL a[];
LL cnm[][];
LL dp[][];
void Init()
{
LL i,j;
for(i=;i<=;i++)
cnm[i][]=;
for(i=;i<=;i++)
{
for(j=;j<=i&&j<=;j++)
{
if(i==j) cnm[i][j]=;
else cnm[i][j]=( cnm[i-][j]+cnm[i-][j-] )%mod;
}
}
}
void solve(LL n)
{
LL i,j,s,Sum=,k;
memset(dp,,sizeof(dp));
for(i=;i<=;i++)
dp[i][]=;
for(i=,s=;i<=n;i++)
{
s=s+a[i];
for(j=;j<=s;j++)
{
dp[i][j]=dp[i-][j];
for(k=;k<=a[i];k++)
if(k<=j)
dp[i][j]=( dp[i][j]+(cnm[j][k]*dp[i-][j-k])%mod )%mod;
if(i==n) Sum=(Sum+dp[i][j])%mod;
}
}
printf("%I64d\n",Sum);
}
int main()
{
LL T=;
LL i,n;
Init();
while(scanf("%I64d",&n)>)
{
for(i=;i<=n;i++)
scanf("%I64d",&a[i]);
printf("Case %I64d: ",++T);
solve(n);
}
return ;
}
HDU 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
首先发现一个很头痛的问题,下面是2个求排列组合的代码 memset(C,,sizeof(C)); ;i<;i++) { C[i][]=; ;j<=;j++) C[i][j]=(C[i-][ ...
- 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个石头) ...
- HDU 4249 A Famous Equation(数位DP)
题目链接:点击打开链接 思路:用d[i][a][b][c][is]表示当前到了第i位, 三个数的i位各自是a,b,c, 是否有进位 , 的方法数. 细节參见代码: #include<cstdio ...
- HDU 3016 Man Down (线段树+dp)
HDU 3016 Man Down (线段树+dp) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- hdu 5025 Saving Tang Monk 状态压缩dp+广搜
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092939.html 题目链接:hdu 5025 Saving Tang Monk 状态压缩 ...
- hdu 5996 dingyeye loves stone(博弈)
题目链接:hdu 5996 dingyeye loves stone 题意: 给你一棵树,树的每一个节点有a[i]个石子,每个人可以将这个节点的石子移向它的父亲,如果没有合法操作,那么就算输,现在给你 ...
- HDU 3341 Lost's revenge AC自动机+dp
Lost's revenge Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)T ...
- HDU 2457 DNA repair(AC自动机+DP)题解
题意:给你几个模式串,问你主串最少改几个字符能够使主串不包含模式串 思路:从昨天中午开始研究,研究到现在终于看懂了.既然是多模匹配,我们是要用到AC自动机的.我们把主串放到AC自动机上跑,并保证不出现 ...
随机推荐
- 通过Jenkins进行提权的一个思路
作者:欧根亲王号 所属团队:Arctic Shell Jenkins是一款由Java编写的开源的持续集成工具,其本身具有执行脚本的功能 在Jenkins的说明信息中列出我们可以使用任意Groovy ...
- Linux 下的 netfilter 认识与常规操作
Linux 下的 netfilter 认识与常规操作 前言 博客写到今天,1年7个月.可是包含所有写作经历,这个时间线可以达到三年. 上次更新了一篇 "镇站之宝" ,也是本站阅读量 ...
- dbus-launch(转)
*NAME* dbus-launch - Utility to start a message bus from a shell script dbus-launch - 从shell脚本启动一个消息 ...
- 安装openssl-devel
安装openssl-devel 0.操作系统为 RHEL6.7 1.描述:当开发人员需要调用openssl的库文件时,需要安装openssl-devel包 2.当根目录(即挂载点为 )的利用率为10 ...
- SQL查询表结构的语句
SELECT tableName=CASE WHEN a.colorder=1 THEN d.name ELSE '' END ,表说明 =CASE WHEN a.colorder=1 THEN IS ...
- QuantLib 金融计算——收益率曲线之构建曲线(1)
目录 QuantLib 金融计算--收益率曲线之构建曲线(1) YieldTermStructure DiscountCurve DiscountCurve 对象的构造 ZeroCurve ZeroC ...
- ubuntu下安装ffmpeg
sudo add-apt-repository ppa:kirillshkrogalev/ffmpeg-next sudo apt-get update sudo apt-get install ff ...
- Log中关于zVideoApp与zChatApp之间的消息传递可以搜索以下字符串
[CSSBConfIPCAgent::OnMessageReceived] (这是zVideoApp端的) 和 [CSSBPTIPCListener::OnMessageReceived] ...
- pygame学习_part1_pygame写程序前的准备工作
import pygame from pygame import * pygame.init() #准备pygame,不准备无法使用功能 pygame.display.set_mode((x,y坐标) ...
- json兼容ie8
今天遇到一个问题,后台传递过来的json对象,在前端解析的时候用JSON.parse(result)方法不好使,查了一下是因为ie浏览器的问题.然后在网上翻了翻,找到了这个办法,可以使这个函数在ie中 ...