554C - Kyoya and Colored Balls

思路:组合数,用乘法逆元求。

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a)) const int MOD=1e9+;
const int N=1e6+;
int a[];
ll fact[N]={}; ll qpow(ll n,ll k)
{
ll ans=;
while(k)
{
if(k&)ans=(ans*n)%MOD;
k>>=;
n=(n*n)%MOD;
}
return ans;
} ll C(ll n,ll k)
{
ll ans=fact[n];
ans=((ans*qpow(fact[n-k],MOD-))%MOD*qpow(fact[k],MOD-))%MOD;
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
int n,sum=;
cin>>n;
for(int i=;i<=n;i++)cin>>a[i],sum+=a[i]; for(ll i=;i<N;i++)
fact[i]=(fact[i-]*i)%MOD; ll ans=;
for(int i=n;i>=;i--)
{
ans=(ans*C(sum-,a[i]-))%MOD;
sum-=a[i];
} cout<<ans<<endl;
return ;
}

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

  1. Codeforces554 C Kyoya and Colored Balls

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

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

  3. Kyoya and Colored Balls(组合数)

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

  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 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. 【47.95%】【codeforces 554C】Kyoya and Colored Balls

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

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

随机推荐

  1. STA分析(四) lib model

    library中的一个cell可以是一个standard cell,IO buffer,或者一个complex IP.其中包含area,functionality,timing,power等相关的信息 ...

  2. ACM数论之旅10---大组合数-卢卡斯定理(在下卢卡斯,你是我的Master吗?(。-`ω´-) )

    记得前几章的组合数吧 我们学了O(n^2)的做法,加上逆元,我们又会了O(n)的做法 现在来了新问题,如果n和m很大呢, 比如求C(n, m) % p  , n<=1e18,m<=1e18 ...

  3. Java获取配置文件跟路径

    一直以为使用new File(相对路径)可以读取class目录下的文件,其实不然.网上查询了一些资料,弄清楚了原理,总结如下: package com.coshaho.learn; import ja ...

  4. linux常用命令:Linux 文件属性详解

    Linux 文件或目录的属性主要包括:文件或目录的节点.种类.权限模式.链接数量.所归属的用户和用户组.最近访问或修改的时间等内容.具体情况如下: 命令:  ls -lih 输出: [root@loc ...

  5. Python入门之面向对象编程(二)python类的详解

    本文通过创建几个类来覆盖python中类的基础知识,主要有如下几个类 Animal :各种属性.方法以及属性的修改 Dog :将方法转化为属性并操作的方法 Cat :私人属性讲解,方法的继承与覆盖 T ...

  6. 01: RestfulAPI与HTTP

    1.1 RestfulAPI与HTTP简介 1.什么是RestfulAPI 1.REST直接翻译:表现层状态转移,实质就是一种面向资源编程的方法 2.REST描述的是在网络中client和server ...

  7. 将DevExpress.Utils.ImageCollection变量的image导出

    private void tspBtnExportExcel_Click(object sender, EventArgs e) { //暂时用来导出图片 string filePath = Syst ...

  8. KMP 初级板子 待更新

    复杂度 O(n+m) 这个博主写的蛮不错的 http://www.cnblogs.com/SYCstudio/p/7194315.html 1.本文中,所有的字符串从0开始编号2.为了在程序中表示方便 ...

  9. 2018 Machine Learning

    2018/8/13 线性模型(西瓜书P53~P73) Optimizer https://blog.csdn.net/u012151283/article/details/78154917 2018/ ...

  10. 2、extract-text-webpack-plugin提取Sass编译的Css

    cnpm install css-loader --save-dev    //css-loader 是将css打包进js cnpm install style-loader --save-dev   ...