Ural 1114(49/600)

本文介绍了一个关于将红球和蓝球放置到一系列盒子中的组合问题,并提供了一段C++代码来解决该问题。该问题的目标是计算所有可能的放置方式的数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

N boxes are lined up in a sequence (1 ≤ N ≤ 20). You have A red balls and B blue balls (0 ≤ A ≤ 15, 0 ≤ B ≤ 15). The red balls (and the blue ones) are exactly the same. You can place the balls in the boxes. It is allowed to put in a box, balls of the two kinds, or only from one kind. You can also leave some of the boxes empty. It’s not necessary to place all the balls in the boxes. Write a program, which finds the number of different ways to place the balls in the boxes in the described way.
Input
Input contains one line with three integers N, A and B separated by space.
Output
The result of your program must be an integer written on the only line of output.
Example
input output
2 1 1
9

可重复组合
说的就是有n个箱子放m个求必须放大于0个随便放有几种放法
就是从n+m-1里选n-1
这个是n+m选n是因为可以不放相当于有n+1个箱子

#include<bits/stdc++.h>
using namespace std;
const unsigned long long maxn=50;
unsigned long long c[maxn][maxn];
void cinit()
{
    for(unsigned long long i=0; i<maxn; i++)
    {
        c[i][0]=c[i][i]=1;
        for(unsigned long long j=1; j<i; j++)
            c[i][j]=(c[i-1][j]+c[i-1][j-1]);
    }
}
unsigned long long n,m,k;
main()
{
    cinit();
    cin>>n>>m>>k;
    unsigned long long aa=c[n+m][n],bb=c[n+k][n];
    cout<<aa*bb<<endl;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值