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

Examples
input

Copy
3
2
2
1
output

Copy
3
input

Copy
4
1
2
3
4
output

Copy
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 题意:
一共有n种颜色的球,同种颜色的球视为完全相同,设置一种放置规则,即上一种颜色球的最后一个必须放在当前颜色球最后一个的前面,问放球的方案数。
题解:
把情况分开考虑,一种颜色一种颜色的往上放,那么dp[i]表示已经放了i种颜色的方案数,a[i]表示第i种颜色的球的个数,sum[i]表示前i种球一共有这么多个,所以当放入i-1种颜色的球后,要把第i种球放一个到最后面以满足题意,然后向前插球,即当前一共有sum[i-1]+a[i]-1个位置,要在这些位置中找a[i]-1个位置放剩下的第i种球,那么这种操作的方法数就是c[sum[i-1+a[i]-1]][a[i]-1]
#include<iostream>
#include<cstdio>
#include<cstring>
#define maxn 1010
#define mod 1000000007
using namespace std;
int n,a[maxn],c[maxn][maxn],dp[maxn],sum[maxn];
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
sum[i]=sum[i-]+a[i];
}
c[][]=;
for(int i=;i<=;i++){
c[i][]=;
for(int j=;j<=;j++)
c[i][j]=(c[i-][j-]+c[i-][j])%mod;
}
dp[]=;
for(int i=;i<=n;i++)
dp[i]=1LL*dp[i-]*c[a[i]-+sum[i-]][a[i]-]%mod;
printf("%d\n",dp[n]);
return ;
}

CF-weekly4 F. 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. 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 ...

  3. Codeforces554 C Kyoya and Colored Balls

    C. Kyoya and Colored Balls Time Limit: 2000ms Memory Limit: 262144KB 64-bit integer IO format: %I64d ...

  4. Kyoya and Colored Balls(组合数)

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

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

  6. 554C - Kyoya and Colored Balls

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

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

  9. 【47.95%】【codeforces 554C】Kyoya and Colored Balls

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. nginx学习(三):nginx的进程模型

    概述 nginx 进程分为 master进程和work进程 1.打开配置文件查看,这里我修改为2 [root@xxx conf]# vim nginx.conf #user nobody; worke ...

  2. GPG 密码修改

    一.前言 相信大家在使用gpp的时候都会遇到这样子都情况: 忘记密码 想要定时更换密码,保证安全 此时不用担心,gpg  的密码更新特别简单. 二.步骤说明 1> 执行命令获 gpg2 --li ...

  3. PHP中查询指定时间范围内的所有日期,月份,季度,年份

    /** * 查询指定时间范围内的所有日期,月份,季度,年份 * * @param $startDate 指定开始时间,Y-m-d格式 * @param $endDate 指定结束时间,Y-m-d格式 ...

  4. 抓包工具之fiddler实战2-设置断点

    Fiddler作为抓工具包,功能强大,作为代理服务器,可以对抓获到的请求或响应进行修改,然后模拟客户端发送新的请求或模拟服务器返回修改后的响应结果. Fiddler中设置断点修改Request Fid ...

  5. 曾Python培训讲师-2年Python开发无包装简历-20191217-可公开

    目录 个人介绍 技能介绍 项目经历 自我评价 简历非完整版,需要完整版看下述信息,禁止任何一切私人用途.转发 我生日是27号,那就27元一份,有需求的来购买!只会涨价不会降价,大概卖10份涨1元:曾P ...

  6. 五分钟搞定 HTTPS 配置,二哥手把手教

    01.关于 FreeSSL.cn FreeSSL.cn 是一个免费提供 HTTPS 证书申请.HTTPS 证书管理和 HTTPS 证书到期提醒服务的网站,旨在推进 HTTPS 证书的普及与应用,简化证 ...

  7. Apache ActiveMQ序列化漏洞(CVE-2015-5254)复现

    Apache ActiveMQ序列化漏洞(CVE-2015-5254)复现 一.漏洞描述 该漏洞源于程序没有限制可在代理中序列化的类.远程攻击者可借助特制的序列化的java消息服务(JMS)Objec ...

  8. Vue基础语法(二)

    class绑定 使用方式:v-bind:class="expression" expression的类型:字符串.数组.对象 style绑定 v-bind:style=" ...

  9. Java生鲜电商平台-高并发核心技术订单与库存实战

    Java生鲜电商平台-高并发核心技术订单与库存实战 一. 问题 一件商品只有100个库存,现在有1000或者更多的用户来购买,每个用户计划同时购买1个到几个不等商品. 如何保证库存在高并发的场景下是安 ...

  10. C#程序员在老项目中用到VB遇到的一次坑

    博主自认为C#基础还不错.但是最近接到一个需求,是用VB写的.万般不愿意,不想接触VB,并不是说VB语言不好,而是我真的不喜欢VB.因为没基础过VB,领导派给的任务,有这个需求,不愿意归不愿意,领导给 ...