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. DevExpress启动时的全屏SplashScreen

    使用DevExpress启动时弹出"正在加载"的Logo,而且是全屏,这种感觉不太好. 原因是使用了DocmentManager控件,当DocmentManager初始化如果耗时较 ...

  2. 完美解决MacOS catalina 升级后Vmware黑屏的问题

    完美解决MacOS catalina 升级后VMware黑屏 1.关闭MacOS的rootless机制 #Rootless机制将成为对抗恶意程序的最后防线 1.尝试关闭Rootless,重启按住 Co ...

  3. javascript中的闭包、函数的toString方法

    闭包: 闭包可以理解为定义在一个函数内部的函数, 函数A内部定义了函数B, 函数B有访问函数A内部变量的权力: 闭包是函数和子函数之间的桥梁: 举个例子: let func = function() ...

  4. saltstack--史上最细致安装攻略!亲测无坑

    准备一台虚拟机node1: [root@linux-node1 pillar]# ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAS ...

  5. Redis高可用集群-哨兵模式(Redis-Sentinel)

     前言 Redis哨兵模式,用现在流行的话可以说就是一个“哨兵机器人”,给“哨兵机器人”进行相应的配置之后,这个"机器人"可以7*24小时工作,它能能够自动帮助你做一些事情,如监控 ...

  6. 现象:SpringApplication.run后面的语句未执行

    下面的两种情况下,红色的log.info中的内容一直没有执行,和预期不符. 看来,需要在@PostConstruct修饰的函数.CommandLineRunner的run方法中调用 另外的线程 来执行 ...

  7. 节点List相关操作

    为方便遍历子节点,lxml将节点list的操作尽可能的与python处理list的方式一样保持一致 创建XML from lxml import etree root = etree.Element( ...

  8. Java生鲜电商平台-深入订单拆单架构与实战

    Java生鲜电商平台-深入订单拆单架构与实战 Java生鲜电商中在做拆单的需求,细思极恐,思考越深入,就会发现里面涉及的东西越来越多,要想做好订单拆单的功能,还是相当有难度, 因此总结了一下拆单功能细 ...

  9. linux下编译安装MariaDB 10.4.7,解决错误:cannot access ‘/auth_pam_tool_dir’: No such file or directory

    编译安装MariaDB 10.4.7,前面的步骤我就不复述了,一切正常没什么问题. 当执行到:scripts/mysql_install_db --basedir=/usr/local/mysql - ...

  10. layui 学习笔记一:layui table 查询、新增、编辑、删除

    一.table数据的呈现(对应查询) 页面代码: @{ ViewBag.Title = "TableGrid"; } @section styles{ <link href= ...