题目链接:

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

    Compressed and uncompressed copies of jQuery files are available. The uncompressed file is best used ...

  2. Unity Texture2D的sRGB(Color Texture)的作用

    在gramma空间下,勾选与否无关. 在liner空间下,勾选shader会自动将读到的像素作gramma矫正,即x的0.45次方 不勾选,shader读到的就是原始的颜色值 然后unity如果选了g ...

  3. Composer的Autoload源码实现2——注册与运行

    前言 上一篇 文章我们讲到了 Composer 自动加载功能的启动与初始化,经过启动与初始化,自动加载核心类对象已经获得了顶级命名空间与相应目录的映射,换句话说,如果有命名空间 'App\Consol ...

  4. DICOM:C-GET服务

    背景: 之前博文对照过多次C-MOVE与C-GET服务的差别,两者最大的差别在于C-GET是基于单个TCP连接的点对点的双方服务.而C-MOVE是基于两个TCP连接的三方服务(详情參见:<DIC ...

  5. HDU-4031-Attack(树状数组)

    Problem Description Today is the 10th Annual of "September 11 attacks", the Al Qaeda is ab ...

  6. [Sdoi2013]随机数生成器(BSGS)

    #include<cstdio> #include<cstring> #include<cmath> #include<iostream> #inclu ...

  7. 【BZOJ3060】[Poi2012]Tour de Byteotia 并查集

    [BZOJ3060][Poi2012]Tour de Byteotia Description 给定一个n个点m条边的无向图,问最少删掉多少条边能使得编号小于等于k的点都不在环上. Input     ...

  8. windows环境下JDK1.8安装

    jdk的安装,在Windows环境下没有什么特殊的选项,只需要“傻瓜式”安装就行(下一步). 如果说有的话,那就是你安装的路径,默认是c盘下的路径,可以根据自己的喜好,安装到自己的意愿目录: 当然,j ...

  9. vim 一键添加注释 自动添加文件头注释

    估计大家也都和我一样用过不少的编辑器,什么notepad2,emeditor,editplus,ultraedit,vs2005,sourceinsight,slickedit,emacs,vim(g ...

  10. Java基础教程:多线程基础(1)——基础操作

    Java:多线程基础(1) 实现多线程的两种方式 1.继承Thread类 public class myThread extends Thread { /** * 继承Thread类,重写RUN方法. ...