首先发现一个很头痛的问题,下面是2个求排列组合的代码

  memset(C,,sizeof(C));
for(int i=;i<;i++)
{
C[i][]=;
for(int j=;j<=;j++)
C[i][j]=(C[i-][j]+C[i-][j-])%MOD;
}
 C[][]=;
for(int i=;i<;i++)
for(int j=;j<=;j++)
if(j==) C[i][j]=C[i-][j];
else C[i][j]=(C[i-][j]+C[i-][j-])%MOD;

其中第一个是刘汝佳上面的代码,不知为什么在杭电OJ上就是WA,第二个就能AC,就路过的大神指点

题目大意

给你一些不同颜色的石头,问选出一些石头排成一排总共有多少种不同排法,不同数量的石头视为不同情况,每个位置上的石头颜色都相同视为相同情况。

分析 

dp+排列组合

dp[i][j] 表示前i堆石子构成长度为j的串的方案数;

状态转移方程是:k为i堆使用的数量

dp[i][j] = (dp[i][j] + dp[i-1][j-k] * C[j][k]%MOD)%MOD;

可以这样想

 dp[ i ][ j ] = dp[ i-1 ][ j ]; //未放入第i种颜色的石头

 dp[ i ][ j ] += dp[ i-1 ][ j - k ] * C[ j ][ k ];  //放入k个第i种颜色的石 

 #include<cstdio>
#include<cstring>
#include<iostream>
#define MOD 1000000007
using namespace std;
typedef long long LL;
LL C[][];
void get_c()
{
memset(C,,sizeof(C));
for(int i=;i<;i++)
{
C[i][]=;
for(int j=;j<=;j++)
C[i][j]=(C[i-][j]+C[i-][j-])%MOD;
}//这一步是错的,不知为啥 C[][]=;
for(int i=;i<;i++)
for(int j=;j<=;j++)
if(j==) C[i][j]=C[i-][j];
else C[i][j]=(C[i-][j]+C[i-][j-])%MOD;
}
LL dp[][];
int main()
{
int cas=,sum,n,num;
LL ans;
get_c();
while(scanf("%d",&n)!=EOF)
{
memset(dp,,sizeof(dp));
dp[][]=;
sum=;
for(int i=;i<=n;i++)
{
scanf("%d",&num);
sum+=num;
for(int k=;k<=num;k++)
{
for(int j=k;j<=sum;j++)
dp[i][j]=(dp[i][j]+(dp[i-][j-k]*C[j][k])%MOD)%MOD;
}
}
ans=;
for(int i=;i<=sum;i++)
ans=(ans+dp[n][i])%MOD;
printf("Case %d: %I64d\n",++cas,ans);
}
return ;
}

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

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

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

  2. [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 ...

  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 5996 dingyeye loves stone(博弈)

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

  5. hdu 4255 A Famous Grid

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4255 A Famous Grid Description Mr. B has recently dis ...

  6. HDU 4256 The Famous Clock

    The Famous Clock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. hdu 1115:Lifting the Stone(计算几何,求多边形重心。 过年好!)

    Lifting the Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  8. HDU 4253 Two Famous Companies

    Two Famous Companies Time Limit: 15000ms Memory Limit: 32768KB This problem will be judged on HDU. O ...

  9. HDU 4251 The Famous ICPC Team Again 主席树

    The Famous ICPC Team Again Problem Description   When Mr. B, Mr. G and Mr. M were preparing for the ...

随机推荐

  1. js使用正则表达式

    参考慕课网示例: 使用js对html输入框内容进行校验: 1. 只能输入5-20个字符,必须以“字母”开头 2. 可以带“数字" “_” “.”的字串 <!DOCTYPE html P ...

  2. 导航栏视图设置 tabbleView 是设置总背景图

    //导航栏视图设置 tabbleView 是设置总背景图 //默认的时白色半透明(有点灰的感觉), UIBarStyleBlack,UIBarStyleBlackTranslucent ,UIBarS ...

  3. C# 轉義字符

    转义字符 意义 ASCII码值(十进制) \a 响铃(BEL) 007 \b 退格(BS) ,将当前位置移到前一列 008 \f 换页(FF),将当前位置移到下页开头 012 \n 换行(LF) ,将 ...

  4. git初识

    下载网上的开发员的项目 git clone https://github.com/xxxxxx/test.git 下载好,进入刚下载的好的test项目目录,可以修改对应的代码,然后 git statu ...

  5. VMWare Workstation 10.0 Preview CN

    What's New in the VMware Workstation Technology Preview July 2013 The VMware Workstation team is exc ...

  6. jQuery get post 碎片(远程html)加载

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. Html.ActionLink , Url.Action

    也来总结一下 以后省的忘了 都是从controller中获取到action名字返回 html.actionlink 返回的是带<a> 标签的超链接 url.action 是返回正常cont ...

  8. Iterator之java.util.ConcurrentModificationException

    在运行以下代码时,会报java.util.ConcurrentModificationException异常, public class Demo { public static void main( ...

  9. hdu 2071

    Ps:输出n个数里最大的 #include "stdio.h" int main(){ ],max; int i,j,n,t; while(~scanf("%d" ...

  10. C++ shared_ptr deleter的实现

    #include <iostream>#include <memory>using namespace std; #include<iostream>class s ...