zoukankan      html  css  js  c++  java
  • codeforces 553 A Kyoya and Colored Balls

    这个题。比赛的时候一直在往dp的方向想,可是总有一个组合数学的部分没办法求,
    纯粹组合数学撸,也想不到办法……
    事实上,非常显然。。


    从后往前推,把第k种颜色放在最后一个,剩下的k球。还有C(剩余的位置,k球的总数目-1)种放法
    然后讨论第k-1种。。。推下去就好了
    可是当时没想到……
    这里要求组合数。因为比較大。用乘法逆元。。。
    当然直接套lucas也是能够的。

    。。。

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

    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.

    Sample test(s)
    Input
    3
    2
    2
    1
    
    Output
    3
    
    Input
    4
    1
    2
    3
    4
    
    Output
    1680
    
    Note

    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;
    }

  • 相关阅读:
    深入了解JVMzz
    正则表达式和Java编程语言1zz
    全世界所有程序员都会犯的错误zz
    C++完美实现Singleton模式zz
    Visual C++6.0 API函数操作技巧集zz光标和鼠标操作
    用next_permutation()生成r组合数,兼VC7的一个bugzz
    基于逆向最大化词表中文分词法zz
    c#.net常用函数列表
    Windows多线程多任务设计初步zz
    在Linux中实现内部进程通信
  • 原文地址:https://www.cnblogs.com/clnchanpin/p/7202369.html
Copyright © 2011-2022 走看看