C. Kyoya and Colored Balls

Time Limit: 2000ms
Memory Limit: 262144KB

64-bit integer IO format: %I64d      Java class name: (Any)

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 i before 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 Input

Input
3
2
2
1
Output
3
Input
4
1
2
3
4
Output
1680

Hint

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

1 2 1 2 3
1 1 2 2 3
2 1 1 2 3 题目大意为,有n种球,编号分别为1234....n,每种球有ci个,问有几种取法,能把盒子里的球拿完,要求是每次取完一种球前,编号比他小的球都取完。 思路:从小往大排列,首先一开始只有一个格子可以放,放入(c1-1)个一号球,并把最后一个一号球放最后,这样一共有(c1+1)个格子,然后在这么多格子里放入(c2-1)个二号球,并把最后一个二号球放在最后,这样一直到最后。
对于 n个格子里放m个球,打个表球行。n个格子放m个球 放的种类就是(n-1个格子放0,1,2,3,4,....mg个球)求和, 推倒一下很容易得到(n个格子放m个球)=(n-1格子放m个球)+(n格子放m-1个球)。这就是推导公式。 代码:
#include <stdio.h>
#include <iostream>
#include <string.h>
#define maxx 1010 using namespace std; int main(){
long long s[maxx][maxx]={};
int t;
int a=;
int q;
long long ans=;
for(int i=;i<maxx;i++)
s[i][]=;
for(int i=;i<maxx;i++)
for(int j=;j<maxx;j++)
s[i][j]=(s[i][j-]+s[i-][j])%;
cin>>t;
for(int i=;i<t;i++){
cin>>q;
ans=(ans*s[a][q-])%;
a+=q;
}
cout<<ans; }

Codeforces554 C Kyoya and Colored Balls的更多相关文章

  1. Codeforces Round #309 (Div. 2) C. Kyoya and Colored Balls 排列组合

    C. Kyoya and Colored Balls Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

  2. Kyoya and Colored Balls(组合数)

    Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  3. C. Kyoya and Colored Balls(Codeforces Round #309 (Div. 2))

    C. Kyoya and Colored Balls Kyoya Ootori has a bag with n colored balls that are colored with k diffe ...

  4. 554C - Kyoya and Colored Balls

    554C - Kyoya and Colored Balls 思路:组合数,用乘法逆元求. 代码: #include<bits/stdc++.h> using namespace std; ...

  5. codeforces 553A A. Kyoya and Colored Balls(组合数学+dp)

    题目链接: A. Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes i ...

  6. CF-weekly4 F. Kyoya and Colored Balls

    https://codeforces.com/gym/253910/problem/F F. Kyoya and Colored Balls time limit per test 2 seconds ...

  7. Codeforces A. Kyoya and Colored Balls(分步组合)

    题目描述: Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  8. codeforces 553A . Kyoya and Colored Balls 组合数学

    Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are ...

  9. Codeforces Round #309 (Div. 2) C. Kyoya and Colored Balls

    Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are ...

随机推荐

  1. 【MySQL】常规操作

    2016.4.10 1.MySQL查看系统当前默认自增列种子值和步长值(全局) 1 show GLOBAL VARIABLES like 'auto_incre%'; 2.MySQL查看具体某一张表的 ...

  2. at 常用命令

    以debian 6.0.1 为例: 服务开启关闭: Usage: /etc/init.d/atd {start|stop|restart|force-reload|status} 设置一次计划任务(a ...

  3. 正则表达式工具RegexBuddy使用教程

    1. 界面介绍  (1)初始界面选项介绍 (2)如何使用匹配 (3)如何使用正则替换 (4)如何使用Debug http://www.cnblogs.com/tsql/p/5860893.html

  4. MySql: 忘记root密码

    win7 + mysql 5.6.35 C:\Windows\system32>mysql --versionmysql Ver 14.14 Distrib 5.6.35, for Win64 ...

  5. 动态选路、RIP协议&&OSPF协议详解

    动态选路.RIP协议&&OSPF协议详解 概念 当相邻路由器之间进行通信,以告知对方每个路由器当前所连接的网络,这时就出现了动态选路.路由器之间必须采用选路协议进行通信,这样的选路协议 ...

  6. 响应式字体(js控制)

    window.onload=function(x){if ('addEventListener' in document) {document.addEventListener('DOMContent ...

  7. tp框架之增删改查

    控制器 <?php namespace Home\Controller; use Think\Controller; class CeShiController extends Controll ...

  8. 【转载】Linux常用命令列表

    原文地址:http://www.cnblogs.com/Javame/p/3968343.html 1 目录与文件操作 1.1 ls(初级) 使用权限:所有人 功能 : 显示指定工作目录下之内容(列出 ...

  9. html标准

    html1.使用双引号2. <img src=""> 不添加/3. <html lang="zh-CN">4. <a class= ...

  10. Win10 UWP vs add github

    vs github 插件 教程 官方教程 点击查看存储库,跳转到 DemoHttp for github