codeforces 553 A Kyoya and Colored Balls
这个题。比赛的时候一直在往dp的方向想,可是总有一个组合数学的部分没办法求,
纯粹组合数学撸,也想不到办法……
事实上,非常显然。。
从后往前推,把第k种颜色放在最后一个,剩下的k球。还有C(剩余的位置,k球的总数目-1)种放法
然后讨论第k-1种。。。推下去就好了
可是当时没想到……
这里要求组合数。因为比較大。用乘法逆元。。。
当然直接套lucas也是能够的。
。。。
2 seconds
256 megabytes
standard input
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.
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.
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.
- 3
- 2
- 2
- 1
- 3
- 4
- 1
- 2
- 3
- 4
- 1680
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的更多相关文章
- 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 ...
- 【47.95%】【codeforces 554C】Kyoya and Colored Balls
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 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 ...
- 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 ...
- Codeforces A. Kyoya and Colored Balls(分步组合)
题目描述: Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- 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 ...
- Codeforces554 C Kyoya and Colored Balls
C. Kyoya and Colored Balls Time Limit: 2000ms Memory Limit: 262144KB 64-bit integer IO format: %I64d ...
- Kyoya and Colored Balls(组合数)
Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- 554C - Kyoya and Colored Balls
554C - Kyoya and Colored Balls 思路:组合数,用乘法逆元求. 代码: #include<bits/stdc++.h> using namespace std; ...
随机推荐
- verilog behavioral modeling--sequential and parallel statements
1.Sequential statement groups the begin-end keywords: .group several statements togethor .cause the ...
- MySQL 之Navicat Premium 12安装使用、pymysql模块使用、sql注入问题的产生与解决
本文内容提要: Navicat Premium 12 的介绍.使用. pymysql模块的使用 sql注入问题的产生与解决 -------------------------------------- ...
- tomcat 修改默认端口8080 为 80端口
首先,找到你的安装目录,如图: 打开server.xml文件,找到8080,如图: 将 8080 改成你想要的端口,如 80 即可.改完后,记得要重启tomcat! 将端口改成 80 后,访问就不需 ...
- node.js中的http.request方法使用说明
http.get(options, callback) 由于该方法属于http模块,使用前需要引入http模块(var http= require(“http”) ) 接收参数: option 数 ...
- 分离焦虑OR责任焦虑
这里是用小孩上幼儿园的事说分离焦虑,转念到成人身上就是责任焦虑. 这周小孩开始上幼儿园了,他很害怕家长离开,我能做的也不多,只是很肯定的告诉他,爸爸就在停车场,下学就来接你,然后从各个 ...
- 五、docker配置镜像加速器之阿里云
1 配置docker加速器 实在忍受不了pull的速度--------- 访问网址: https://dev.aliyun.com/search.html 点击管理中心: 根据操作稳定配置:
- 【JavaScript 1—基础知识点】:宏观概述
导读:JavaScript是一门新的(也可以说是旧的或者半新语言),里面有很多的知识点都能和已有的知识产生共鸣.但是,虽然简单,相同点也有很多,也有不同点.我脑袋也不好使,所以对于我来说,还是有必要再 ...
- Terracotta2
Terracotta 3.2.1简介 (二) Terracotta分布式缓存EhcacheQuartzTerracotta的web session方案 高效.高可用的Web Session解决方案 ...
- 如何解决 错误code signing is required for product type 'xxxxx' in SDK 'iOS 8.2'
如何解决 错误code signing is required for product type 'xxxxx' in SDK 'iOS 8.2' 大家在做真机调试的时候,或许会遇到这样的问题,那如何 ...
- NOJ——1642简单的图论问题?(BFS+优先队列)
[1642] 简单的图论问题? 时间限制: 5000 ms 内存限制: 65535 K 问题描述 给一个 n 行 m 列的迷宫,每个格子要么是障碍物要么是空地.每个空地里都有一个权值.你的 任务是从找 ...