CF-weekly4 F. Kyoya and Colored Balls
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 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.
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 题意:
一共有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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 554C - Kyoya and Colored Balls
554C - Kyoya and Colored Balls 思路:组合数,用乘法逆元求. 代码: #include<bits/stdc++.h> using namespace std; ...
- Codeforces A. Kyoya and Colored Balls(分步组合)
题目描述: Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- 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 ...
- 【47.95%】【codeforces 554C】Kyoya and Colored Balls
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- Luogu P5298 [PKUWC2018]Minimax
好劲的题目啊,根本没往线段树合并方面去想啊 首先每种权值都有可能出现,因此我们先排个序然后一个一个求概率 由于此时数的值域变成\([1,m]\)(离散以后),我们可以设一个DP:\(f_{x,i}\) ...
- 基于Docker的Consul服务发现集群搭建
在去年的.NET Core微服务系列文章中,初步学习了一下Consul服务发现,总结了两篇文章.本次基于Docker部署的方式,以一个Demo示例来搭建一个Consul的示例集群,最后给出一个HA的架 ...
- php 数组赋值
结果: 结论:第一种方式的运行速度是第二种方式的二倍左右.
- 接口测试用例yaml格式数据
1. login.yaml yaml文件 - name # 添加减号可以把用例转为list,每一部分是一个字典 url: /api/user/login method: post data: # 存放 ...
- H5纯前端生成Excel表格
H5纯前端生成Excel表格方法如下: <!DOCTYPE html> <html> <head> <title></title> < ...
- vue中template的作用及使用
先来看一个需求:下图div用v-for做了列表循环,现在想要span也一起循环,应该怎么做? 有3种方法可以实现 ①:直接用v-for对span也循环一次(该方法虽然可以使用,但不要用这种方式,因为 ...
- Docker - 快速入门(一)
概念 下面这三个概念一开始可能不好理解,等大家跟着博客把例子做完了,再回头来看应该就能理解了. docker image # docker镜像 镜像就是一个只读的模板.镜像可以用来创建Docker容 ...
- .net core程序强制以管理员权限启动
当我们编写windows程序的时候,很多时候需要程序默认以管理员权限运行,以前在.net 程序中直接新建一个app.manifest,设置requestedExecutionLevel 节点即可 &l ...
- C# Newtonsoft.Json 读取文件,返回json字符串
第一种方法: public object getData2() { string content; using (StreamReader sr = new StreamReader(Server.M ...
- 爬虫框架-selenium
selenium介绍: selenium最初是一个自动化测试工具,而爬虫中使用它主要是为了解决requests无法直接执行JavaScript代码的问题 selenium本质是通过驱动浏览器,完全模拟 ...