这个题。比赛的时候一直在往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. python实现FTP

    原文地址:https://www.cnblogs.com/huangxm/p/6274645.html#undefined FTP服务的主动模式和被动模式 在开始之前,先聊一下FTP的主动模式和被动模 ...

  2. 剑指Offer(书):树的子结构

    题目:输入两棵二叉树A,B,判断B是不是A的子结构.(ps:我们约定空树不是任意一个树的子结构) 分析:关于二叉树大部分适应于递归结构. public boolean HasSubtree(TreeN ...

  3. myeclipse 改变模版

    一.修改Servlet的默认模板代码 使用MyEclipse创建Servlet时,根据默认的Servlet模板生成的Servlet代码如下: 1 package gacl.servlet.study; ...

  4. Android 8.0 adb shell dumpsys activity activities | findstr mFocusedActivity 获取当前的 activity 显示空的

    adb shell dumpsys activity activities | findstr mFocusedActivity Android 7.0 现象: Android 8.0 现象: 改用: ...

  5. x86保护模式 二 分段管理机制

    分段管理机制 段选择子和偏移地址的二维虚拟地址转换为一维的线性地址 一  段定义和虚拟地址到线性地址的转换 三个参数定义段:段基地址    段界限  和段属性    同时也是段描述符的结构 段基地址为 ...

  6. spring实战 — spring数据库事务

    欢迎加入程序员的世界,添物科技为您服务. 欢迎关注添物网的微信(微信号:tianwukeji),微博(weibo.com/91tianwu/),或下载添物APP,及时获取最新信息. 免费加入QQ群:5 ...

  7. hdu 4251 The Famous ICPC Team Again划分树入门题

    The Famous ICPC Team Again Time Limit: 30000/15000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  8. 【NOI Linux】复习一波命令行

    $linux$ 终端真是用不惯. 假设 a 是一个可执行文件( $linux$ 下的可执行文件没有后缀 ) 1. size a 计算一个程序的静态内存(全局数组变量.栈空间.堆空间等),单位是字节.除 ...

  9. wsgi 简介

    原文博客地址 http://blog.csdn.net/on_1y/article/details/18803563

  10. N皇后-位运算优化

    N皇后问题 时间限制: 5 Sec  内存限制: 128 MB 题目描述 魔法世界历史上曾经出现过一个伟大的罗马共和时期,出于权力平衡的目的,当时的政治理论家波利比奥斯指出:“事涉每个人的权利,绝不应 ...