标签:
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
1 2 1 2 3
1 1 2 2 3
2 1 1 2 3
题目大意为,有n种球,编号分别为1234....n,每种球有ci个,问有几种取法,能把盒子里的球拿完,要求是每次取完一种球前,编号比他小的球都取完。
思路:从小往大排列,首先一开始只有一个格子可以放,放入(c1-1)个一号球,并把最后一个一号球放最后,这样一共有(c1+1)个格子,然后在这么多格子里放入(c2-1)个二号球,并把最后一个二号球放在最后,这样一直到最后。
对于 n个格子里放m个球,打个表球行。n个格子放m个球 放的种类就是(n-1个格子放0,1,2,3,4,....mg个球)求和, 推倒一下很容易得到(n个格子放m个球)=(n-1格子放m个球)+(n格子放m-1个球)。这就是推导公式。
代码:
#include <stdio.h> #include <iostream> #include <string.h> #define maxx 1010 using namespace std; int main(){ long long s[maxx][maxx]={0}; int t; int a=1; int q; long long ans=1; for(int i=0;i<maxx;i++) s[i][0]=1; for(int i=1;i<maxx;i++) for(int j=1;j<maxx;j++) s[i][j]=(s[i][j-1]+s[i-1][j])%1000000007; cin>>t; for(int i=0;i<t;i++){ cin>>q; ans=(ans*s[a][q-1])%1000000007; a+=q; } cout<<ans; }
Codeforces Round#309 C Kyoya and Colored Balls
标签:
原文地址:http://www.cnblogs.com/zhangyifang/p/5663560.html