http://codeforces.com/problemset/problem/553/A

A. Kyoya and Colored Balls
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Kyoya Ootori has a bag with n colored balls that are colored with k different
colors. The colors are labeled from 1 to k.
Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color ibefore
drawing the last ball of color i + 1 for all i from 1 to k - 1.
Now he wonders how many different ways this can happen.

Input

The first line of input will have one integer k (1 ≤ k ≤ 1000)
the number of colors.

Then, k lines will follow. The i-th
line will contain ci,
the number of balls of the i-th color (1 ≤ ci ≤ 1000).

The total number of balls doesn't exceed 1000.

Output

A single integer, the number of ways that Kyoya can draw the balls from the bag as described in the statement, modulo 1 000 000 007.

Sample test(s)
input
3
2
2
1
output
3
input
4
1
2
3
4
output
1680
Note

In the first sample, we have 2 balls of color 1, 2 balls of color 2, and 1 ball of color 3. The three ways for Kyoya are:

1 2 1 2 3
1 1 2 2 3
2 1 1 2 3
/**
CF 553A 组合DP
题目大意:在一个口袋里有n种颜色的小球,每一个小球有ai个,如今从口袋里依次取出小球,要求第i种颜色的最后一个球要在第i+1种颜色的最后一个小球的前面被拿出
问有多少种取法?
解题思路:考虑第i种球最后一个球取出来之前前i-1种球必须已经安排好了,那么对于第i种球的ai-1个球仅仅需插入sum[i]之间就可以,故dp[i]=dp[i-1]*c[sum[i]-1][a[i01]];
*/
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long LL;
const LL mod=1e9+7;
const int maxn=1200;
LL c[maxn][maxn],dp[maxn],a[maxn];
int n;
void init()
{
c[0][0]=1;
for(int i=1;i<1110;i++)
{
c[i][0]=c[i][1]=1;
for(int j=1;j<=i;j++)
{
c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
}
}
/*for(int i=1;i<=10;i++)
{
for(int j=0;j<=i;j++)
{
printf("%d ",c[i][j]);
}
printf("\n");
}*/
}
int main()
{
init();
while(~scanf("%d",&n))
{
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
}
int sum=0;
memset(dp,0,sizeof(dp));
dp[0]=1;
for(int i=1;i<=n;i++)
{
sum+=a[i];
dp[i]=(dp[i-1]*c[sum-1][a[i]-1])%mod;
}
printf("%lld\n",dp[n]);
}
return 0;
}

CF 553A 组合DP的更多相关文章

  1. CF 445A 简单DP

    今天早上找一道题的bug,还是找不出来,下午刷了几道水题,晚上准备回家的事, 然后本来想打CF的,一看,数学场,不打了. 这道题的题意: 给出一个序列,每次你可以从这个序列里面选择一个数ak,删除,然 ...

  2. HDU 4632 CF 245H 区间DP(回文)

    先说HDU 4632这道题,因为比较简单,题意就是给你一个字符串,然后给你一个区间,叫你输出区间内所有的回文子序列,注意是回文子序列,不是回文字串. 用dp[i][j]表示区间[i,j]内的回文子序列 ...

  3. CF 219D 树形DP

    CF 219D [题目链接]CF 219D [题目类型]树形DP &题意: 给一个n节点的有向无环图,要找一个这样的点:该点到其它n-1要逆转的道路最少,(边<u,v>,如果v要到 ...

  4. [Bzoj3193][JLOI2013]地形生成 (排列组合 + DP)

    3193: [JLOI2013]地形生成 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 459  Solved: 223[Submit][Status ...

  5. CF 335B. Palindrome(DP)

    题目链接 挺好玩的一个题,1Y... #include <cstdio> #include <cstring> #include <iostream> using ...

  6. acdream 1412 2-3Trees (组合+DP)

    题意:2-3树的每个结点(除了叶子外)有2或3个孩子(分支),假设是一个满2-3树,那么给出叶子的数量,求这样的树有多少棵.(注:有2个孩子的结点视为相同,有3个孩子的结点视为相同,比如倒数第2层有4 ...

  7. cf 148D 概率DP

    题意:原来袋子里有w只白鼠和b只黑鼠龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老师谁就赢.王妃每次抓一只老鼠,龙每次抓完一只老鼠之后会有一只老鼠跑出来.每次抓老鼠和跑出来的老鼠都是随机的.如果两个人都没 ...

  8. HDU4532(组合DP)

    题目:安排座位 解析:http://www.douban.com/note/269136472/ #include <iostream> #include <string.h> ...

  9. AGC 001E.BBQ Hard(组合 DP)

    题目链接 \(Description\) 给定长为\(n\)的两个数组\(a,b\),求\[\sum_{i=1}^n\sum_{j=i+1}^n\binom{a_i+a_j+b_i+b_j}{a_i+ ...

随机推荐

  1. shakes hands

    Description On February, 30th n students came in the Center for Training Olympiad Programmers (CTOP) ...

  2. DELPHI XE7 新的并行库

    DELPHI XE7 的新功能列表里面增加了并行库System.Threading, System.SyncObjs. 为什么要增加新的并行库? 还是为了跨平台.以前要并行编程只能从TThread类继 ...

  3. HDU 4668 Finding string (解析字符串 + KMP)

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 题意:给出一个压缩后的串,以及一个模式串,问模式串 ...

  4. 菜鸟版JAVA设计模式—从买房子看代理模式

    今天学习了代理模式. 相对于适配器模式,或者说装饰器模式,代理模式理解起来更加简单. 代理这个词应该比較好理解,取代去做就是代理. 比方,我们买卖房子,那么我们会找中介,我要卖房子,可是我们没有时间去 ...

  5. Android菜鸟的成长笔记(3)——给QQ登录界面说So Easy

    原文:Android菜鸟的成长笔记(3)--给QQ登录界面说So Easy 上一篇:Android菜鸟的成长笔记(2)--第一个Android应用 我们前面已经做了第一个Android应用程序,虽然有 ...

  6. Linux统计文件/目录数量ls -l | grep "^-" | wc -l匹配开头和结尾

    Linux统计文件数量 ls -l | grep "^-" | wc -l “^-”  一般文件 “^d” 目录文件 shell/vim中^表示开头 cat repatterns ...

  7. 同步linux服务器的时间

    1:看系统时间的时候发现有点儿误差,大概在2分钟左右. 于是想自动同步系统的时间. 2:找到ntpdate命令,没有就安装.debian(apt-get install ntpdate) 3:获取时间 ...

  8. 在Delphi中使用C++对象(两种方法,但都要改造C++提供的DLL)

    Delphi是市场上最好的RAD工具,但是现在C++占据着主导地位,有时针对一个问题很难找到Delphi或Pascal的解决方案.可是却可能找到了一个相关的C++类.本文描述几种在Delphi代码中使 ...

  9. sql plus 抢救数据(測)

    有索引 --运行plsql脚本 DECLARE  TYPE RowIDTab ISTABLE OF ROWID INDEXBY BINARY_INTEGER;    CURSORc1 IS selec ...

  10. AngularJs打造一个简易权限系统

    AngularJs打造一个简易权限系统 一.引言 上一篇博文已经向大家介绍了AngularJS核心的一些知识点,在这篇博文将介绍如何把AngularJs应用到实际项目中.本篇博文将使用AngularJ ...