题目链接:

A. Kyoya and Colored Balls

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

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.

Examples
input
3
2
2
1
output
3
input
4
1
2
3
4
output
1680

题意:

k种颜色的求,第i种颜色的球有a[i]个,现在要求第i种球的最后一个一定在第i+1种球的最后一个的前边,问有多少种拿法;

思路:

dp[i]表示前i种球的拿法的方案数,再拿第i+1种球的时候,先取出一个放在最后,然后剩下a[i+1]-1个球,前边有sum个球,形成sum+1个空挡,相当于把a[i+1]-1个相同的小球放在sum+1个不同的盒子中,看这里总结的球盒汇总;

AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=3e6+10;
const int maxn=1e3+20;
const double eps=1e-12; int a[maxn];
LL dp[maxn];
LL pow_mod(LL x,LL y)
{
LL s=1,base=x;
while(y)
{
if(y&1)s=s*base%mod;
base=base*base%mod;
y>>=1;
}
return s;
}
LL C(int x,int y)
{
LL s1=1,s2=1;
for(int i=x;i>x-y;i--)s1=s1*i%mod;
for(int i=1;i<=y;i++)s2=s2*i%mod;
return s1*pow_mod(s2,mod-2)%mod;
}
int main()
{
int n;
read(n);
For(i,1,n)read(a[i]);
int sum=a[1];
dp[1]=1;
for(int i=2;i<=n;i++)
{
dp[i]=dp[i-1]*C(a[i]-1+sum,sum)%mod;
sum+=a[i];
}
print(dp[n]);
return 0;
}

  

codeforces 553A A. Kyoya and Colored Balls(组合数学+dp)的更多相关文章

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

  2. codeforces 553 A Kyoya and Colored Balls

    这个题.比赛的时候一直在往dp的方向想,可是总有一个组合数学的部分没办法求, 纯粹组合数学撸,也想不到办法-- 事实上,非常显然.. 从后往前推,把第k种颜色放在最后一个,剩下的k球.还有C(剩余的位 ...

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

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

  4. Codeforces554C:Kyoya and Colored Balls(组合数学+费马小定理)

    Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are ...

  5. Codeforces554C:Kyoya and Colored Balls(组合数学计算+费马小定理)

    题意: 有k种颜色,每种颜色对应a[i]个球,球的总数不超过1000 要求第i种颜色的最后一个球,其后面接着的必须是第i+1种颜色的球 问一共有多少种排法 Sample test(s) input o ...

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

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

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

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

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

随机推荐

  1. VS2019取消git源代码管理

    VS2019->工具->选项->源代码管理->插件管理 详见下图

  2. 【BZOJ3993】[SDOI2015]星际战争 二分+最大流

    [BZOJ3993][SDOI2015]星际战争 Description 3333年,在银河系的某星球上,X军团和Y军团正在激烈地作战.在战斗的某一阶段,Y军团一共派遣了N个巨型机器人进攻X军团的阵地 ...

  3. MATLAB循环结构:break+continue+嵌套

    break语句:终止当前循环,继续执行循环语句的下一语句: continue语句:跳过循环体的后面语句,开始下一个循环: 例:求[100,200]之间第一个能被21整除的整数 :200 %循环语句 ) ...

  4. visual studio code (vscode)像 sublime text 的 ctrl+d 一样多光标选中

    快捷键是 ctrl+m ,返回上一个选中时ctrl+u. 文件 ==>首选项 ==>键盘快捷键() 里面可以查到,下一个是“将选择添加到下一个查找匹配项”,返回上一个是“cursorund ...

  5. ibatis中井号跟美元符号区别(#.$)

    1.#可以进行预编译,进行类型匹配,#变量名# 会转化为 jdbc 的 类型 $不进行数据类型匹配,$变量名$就直接把 $name$替换为 name的内容 例如: select * from tabl ...

  6. shell编程1

    shell编程1 一.shell基础正则表达式 1.正则表达式和通配符 正则表达式是用来在文件中匹配符合条件的字符串,正则式包含匹配.(grep awk sed) 通配符是用来匹配符合条件的文件名,通 ...

  7. 用Pythonic方式来思考

    一门语言的编程习惯是由用户来确立的.这些年来,Python开发者用Pythonic这个形容词来描述那种符合特定风格的代码. 这种Pyhtonic风格,既不是严密的规范,也不是由编译器强加给开发者的规则 ...

  8. P3160 [CQOI2012]局部极小值

    题目 P3160 [CQOI2012]局部极小值 一眼就是状压,接下来就不知道了\(qwq\) 做法 我们能手玩出局部小值最多差不多是\(8,9\)个的样子,\(dp_{i,j}\)为填满\(1~i\ ...

  9. 左侧图片 右侧块的实现方法---解决3像素bug的一种解决方案,不用浮动用绝对定位和margin-left

    google的实现方式是: <div class="mw"> <a href="/" id="mlogo">  &l ...

  10. java 遍历数组的几种方式

    本文总结自: https://www.cnblogs.com/hellochennan/p/5373186.html 1. 传统方式 非常简单的for循环 int[] a = {1, 2, 3, 4} ...