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

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
 
Recommend
 
题意:给n种石头,每种m个。
        求组成长度 小于等于k的全排列的个数。
解题思路:
 
别人的思路:
  dp[ i ][ j ]表示:考虑前i种石头构成的长度为j的序列的个数。
  转台转移方程:
    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 ]; //!!!
      Cnm = Cn-1m-1 + Cn-1 1
   其中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 ****的更多相关文章

  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

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

  3. 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个石头) ...

  4. HDU 4249 A Famous Equation(数位DP)

    题目链接:点击打开链接 思路:用d[i][a][b][c][is]表示当前到了第i位, 三个数的i位各自是a,b,c, 是否有进位 , 的方法数. 细节參见代码: #include<cstdio ...

  5. HDU 3016 Man Down (线段树+dp)

    HDU 3016 Man Down (线段树+dp) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  6. hdu 5025 Saving Tang Monk 状态压缩dp+广搜

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092939.html 题目链接:hdu 5025 Saving Tang Monk 状态压缩 ...

  7. hdu 5996 dingyeye loves stone(博弈)

    题目链接:hdu 5996 dingyeye loves stone 题意: 给你一棵树,树的每一个节点有a[i]个石子,每个人可以将这个节点的石子移向它的父亲,如果没有合法操作,那么就算输,现在给你 ...

  8. 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 ...

  9. HDU 2457 DNA repair(AC自动机+DP)题解

    题意:给你几个模式串,问你主串最少改几个字符能够使主串不包含模式串 思路:从昨天中午开始研究,研究到现在终于看懂了.既然是多模匹配,我们是要用到AC自动机的.我们把主串放到AC自动机上跑,并保证不出现 ...

随机推荐

  1. 洛谷P5279 [ZJOI2019]麻将(乱搞+概率期望)

    题面 传送门 题解 看着题解里一堆巨巨熟练地用着专业用语本萌新表示啥都看不懂啊--顺便\(orz\)余奶奶 我们先考虑给你一堆牌,如何判断能否胡牌 我们按花色大小排序,设\(dp_{0/1,i,j,k ...

  2. Display all 2232 possibilities? (y or n)

    Linux下我在没输入任何命令的情况下摁了两下tab键,然后就出现了这个提示:Display all 2232 possibilities? (y or n) 我觉得摁y的话就会显示所有的现阶段命令. ...

  3. [Objective-C语言教程]类和对象(24)

    Objective-C编程语言的主要目的是为C编程语言添加面向对象,类是Objective-C的核心特性,支持面向对象编程,通常称为用户定义类型. 类用于指定对象的形式,它将数据表示和方法组合在一起, ...

  4. [Virtualization] VMware虚拟机三种网络模式详解(转)

    原文:http://www.linuxidc.com/Linux/2016-09/135521.htm

  5. 架构师养成记--16.disruptor并发框架中RingBuffer的使用

    很多时候我们只需要消息中间件这样的功能,那么直需要RinBuffer就可以了. 入口: import java.util.concurrent.Callable; import java.util.c ...

  6. C#-WebForm-★★★LinQ-数据的条件组合查询并进行分页展示(未加各种限定)★★★

    前台代码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.as ...

  7. Markdown基本语法总结

    一.标题 在想要设置为标题的文字前面加#来表示 一个#是一级标题,二个#是二级标题,以此类推.支持六级标题. 注:标准语法一般在#后跟个空格再写文字. 示例: # 这是一级标题 ## 这是二级标题 # ...

  8. Ubuntu18.04配制阿里巴巴的源

    配制阿里巴巴的源步骤 使用阿里巴巴的开源镜像:https://opsx.alibaba.com/mirror 然后选择ubuntu的帮助选项,复制ubuntu18.04镜像源 设置root账户密码: ...

  9. 一、OPENERP 的一个demo

    安装好OPENERP后,使用 ps -aux|grep openerp 从输出的内容可以得到OPENERP的安装信息, /usr/bin/python /usr/bin/openerp-server ...

  10. 1、 小白带你入坑xamarin系列之环境搭建和准备

    重点提示 由于xamarin发展更新很快 目前教程部分内容已经过时 请注意下载最新版本   2018.05.23 www.xamarin.com 1. 小白带你入坑xamarin系列之环境搭建和准备 ...