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. SQL 2008 数据库迁移

    1,改动迁移路径 USE master GO ALTER DATABASE 数据库名  --主数据 MODIFY FILE(NAME='数据库名', FILENAME='F:\DataBase\数据库 ...

  2. Rationnal Rose2003安装并破解

    1.安装Rational Rose2003时,在需选择安装项的时候,只选择Rational Rose EnterPrise Edition即可,不需选择其他项,之后选择“DeskTop Install ...

  3. 使用OVS

    创建节点: 需要在组件上引用OVS组件WDR_OVS:引用后需要更改添加节点属性值如下: 布局如下: 在view中也添加ovs组件 新建事件方法: ON_EVENT 代码如下: METHOD on_e ...

  4. nginx的sendfile指令的作用

    linux为了解决对读文件产生的从应用空间到内核空间复制数据产生的效率影响引进了零拷贝.什么是零拷贝?这里就不多说了,请参考http://blog.csdn.net/crazyguang/articl ...

  5. MVC3和MVC4中CRUD操作

    MVC3中EF实现的CRUD操作 public class HomeController : Controller { // // GET: /Home/ CarModelContainer db = ...

  6. HDU 1254 推箱子游戏(搞了一下午。。。)

    中文题目:http://acm.hdu.edu.cn/showproblem.php?pid=1254 一开始常规的人用来做主导,想着想着不对劲,其实是箱子为主导,人只是箱子能否推进的一个判断. 可以 ...

  7. disruptor流程

    这里先不提那些编译器方面的优化.只看一下基于无锁环形队列的生产者消费者模型的工作流程.上一个图先: 当中,buffer是一个数组,用来模拟环形队列. slowest_reader记录最慢的reader ...

  8. Android:通知栏的使用

    非常久没有使用Android的通知功能了,今天把两年前的代码搬出来一看.发现非常多方法都废弃了,代码中各种删除线看的十分不爽.于是乎,打开Google,查看官方文档.学习最新的发送通知栏消息的方法. ...

  9. Referer反反盗链

    0x00 前言 最近用Python非常多,确实感受到了Python的强大与便利.但同时我并没有相见恨晚的感觉,相反我很庆幸自己没有太早接触到Python,而是基本按着C→C++→Java→Python ...

  10. 使用HashMap须要注意的事儿:不要暴露Map.entry给外部不可信代码Map.entrySet()

    Map/HashMap是java中一种非经常常使用的数据结构,一般我们在应用中做的事情就是调用put向容器写入数据或者是get从容器读取数据. Map.entrySet()这种方法返回了键值对的集合, ...