A. Kyoya and Colored Balls_排列组合,组合数

本文解析了Codeforces Round #309 (Div.1)中A题「彩色球的排列方式」的解题思路,包括从后往前思考的方法、递推公式以及组合数的使用,详细阐述了如何通过组合数学解决此类问题。

Codeforces Round #309 (Div. 1)

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

解题报告:

1、可以从后往前思考,先把第n种颜色的,最后一个球放到最后,然后将这个颜色的其余的球随便放,然后将第(n-1)种颜色的球放到,之前放的球的最前一个的前面,递推下去。

2、递推公式:

for(int i=n;i>=1;i--)
{
    if(cnt[i]==0) continue;
    ans=(ans*C[c-1][cnt[i]-])% mod;
    c-=cnt[i];
}

3、组合数递推公式:

void init()
{
    memset(C, 0, sizeof(C));
    C[0][0] = 1;
    C[1][0] = C[1][1] = 1;
    for(int i = 2; i <= 1000; ++i)
    {
        C[i][0] = C[i][i] = 1;
        for(int j = 1; j < i; ++j)
        {
            C[i][j] = (C[i-1][j-1] + C[i-1][j]) % mod;
        }
    }
}

 

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int maxn = 1010;
const ll  mod  = 1000000007;
ll C[maxn][maxn];

void init()
{
    memset(C, 0, sizeof(C));
    C[0][0] = 1;
    C[1][0] = C[1][1] = 1;
    for(int i = 2; i <= 1000; ++i)
    {
        C[i][0] = C[i][i] = 1;
        for(int j = 1; j < i; ++j)
        {
            C[i][j] = (C[i-1][j-1] + C[i-1][j]) % mod;
        }
    }
}

int cnt[maxn];

int main()
{

    init();
    int n;
    int c = 0;
    ll  ans = 1;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &cnt[i]);
        c += cnt[i];
    }

    for(int i = n; i >= 1; i--)
    {
        if(cnt[i] == 0) continue;
        ans = (ans * C[c-1][cnt[i]-1]) % mod;
        c -= cnt[i];
    }

    cout << ans << endl;

    return 0;
}

 

转载于:https://www.cnblogs.com/TreeDream/p/5346542.html

dnSpy是目前业界广泛使用的一款.NET程序的反编译工具,支持32位和64位系统环境。它允许用户查看和编辑.NET汇编和反编译代码,以及调试.NET程序。该工具通常用于程序开发者在维护和调试过程中分析程序代码,尤其在源代码丢失或者无法获取的情况下,dnSpy能提供很大的帮助。 V6.1.8版本的dnSpy是在此系列软件更新迭代中的一个具体版本号,代表着该软件所具备的功能与性能已经达到了一个相对稳定的水平,对于处理.NET程序具有较高的可用性和稳定性。两个版本,即32位的dnSpy-net-win32和64位的dnSpy-net-win64,确保了不同操作系统架构的用户都能使用dnSpy进行软件分析。 32位的系统架构相较于64位,由于其地址空间的限制,只能支持最多4GB的内存空间使用,这在处理大型项目时可能会出现不足。而64位的系统能够支持更大的内存空间,使得在处理大型项目时更为方便。随着计算机硬件的发展,64位系统已经成为了主流,因此64位的dnSpy也更加受开发者欢迎。 压缩包文件名“dnSpy-net-win64.7z”和“dnSpy-net-win32.7z”中的“.7z”表示该压缩包采用了7-Zip压缩格式,它是一种开源的文件压缩软件,以其高压缩比著称。在实际使用dnSpy时,用户需要下载对应架构的压缩包进行解压安装,以确保软件能够正确运行在用户的操作系统上。 dnSpy工具V6.1.8版本的发布,对于.NET程序员而言,无论是32位系统还是64位系统用户,都是一个提升工作效率的好工具。用户可以根据自己计算机的操作系统架构,选择合适的版本进行下载使用。而对于希望进行深度分析.NET程序的开发者来说,这个工具更是不可或缺的利器。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值