这个题。比赛的时候一直在往dp的方向想,可是总有一个组合数学的部分没办法求,

纯粹组合数学撸,也想不到办法……

事实上,非常显然。。

从后往前推,把第k种颜色放在最后一个,剩下的k球。还有C(剩余的位置,k球的总数目-1)种放法

然后讨论第k-1种。。。推下去就好了

可是当时没想到……

这里要求组合数。因为比較大。用乘法逆元。。。

当然直接套lucas也是能够的。

。。。

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
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 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
#include<iostream>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
ll qpow(ll a,ll b)
{
ll ans=1,c=a;
while(b)
{
if(b&1)
ans=ans*c%mod;
b>>=1;
c=c*c%mod;
}
return ans;
}
ll fac[1000010];
ll work(int a,int b)
{
return fac[a]*qpow(fac[b]*fac[a-b]%mod,mod-2)%mod;
}
int a[1010];
int main()
{
fac[0]=1;
for(int i=1;i<=1000000;i++)
fac[i]=fac[i-1]*i%mod;
int n;
cin>>n;
int sum=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
sum+=a[i];
}
ll ans=1;
for(int i=n-1;i>-1;i--)
{
ans=ans*work(sum-1,a[i]-1)%mod;
sum-=a[i];
}
cout<<ans;
}

codeforces 553 A Kyoya and Colored Balls的更多相关文章

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

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

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

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

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

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

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

  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. Codeforces554 C Kyoya and Colored Balls

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

  8. Kyoya and Colored Balls(组合数)

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

  9. 554C - Kyoya and Colored Balls

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

随机推荐

  1. PHP中文件锁与进程锁的使用区别

    php中文网的一篇文章,收为己用了.源地址: http://www.php.cn/php-weizijiaocheng-376853.html 本篇文章主要介绍了PHP 文件锁与进程锁的使用示例,小编 ...

  2. IRQ中断处理流程

    基于Linux2.6.30.4分析IRQ中断的处理流程. 1.中断入口 /* arch/arm/kenel/entry-armv.S*/ b vector_irq + stubs_offset 2.v ...

  3. C语言文件操作 FILE结构体

    内存中的数据都是暂时的,当程序结束时,它们都将丢失.为了永久性的保存大量的数据,C语言提供了对文件的操作. 1.文件和流 C将每个文件简单地作为顺序字节流(如下图).每个文件用文件结束符结束,或者在特 ...

  4. LeetCode(95) Unique Binary Search Trees II

    题目 Given n, generate all structurally unique BST's (binary search trees) that store values 1-n. For ...

  5. 正负无穷float('inf')的一些用法

    Python中可以用如下方式表示正负无穷: float("inf"), float("-inf") 利用 inf 做简单加.乘算术运算仍会得到 inf > ...

  6. Leetcode 368.最大整除子集

    最大整除子集 给出一个由无重复的正整数组成的集合,找出其中最大的整除子集,子集中任意一对 (Si,Sj) 都要满足:Si % Sj = 0 或 Sj % Si = 0. 如果有多个目标子集,返回其中任 ...

  7. MySQL binlog_rows_query_log_events在线设置无效

    binlog_rows_query_log_events 对binlog_format=row有效,设为true后可以在binary log中记录原始的语句 官方文档显示binlog_rows_que ...

  8. Android单个按钮自定义Dialog

    代码改变世界 Android单个按钮自定义Dialog dialog_layout.xml <?xml version="1.0" encoding="utf-8& ...

  9. BZOJ 2005 [Noi2010]能量采集 ——Dirichlet积

    [题目分析] 卷积一卷. 然后分块去一段一段的求. O(n)即可. [代码] #include <cstdio> #include <cstring> #include < ...

  10. [图论训练]BZOJ 1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路【floyd】

    Description     农夫约翰正驾驶一条小艇在牛勒比海上航行.     海上有N(1≤N≤100)个岛屿,用1到N编号.约翰从1号小岛出发,最后到达N号小岛.一 张藏宝图上说,如果他的路程上 ...