【暑训排位 #6 B】 排列组合

78 篇文章 0 订阅
37 篇文章 0 订阅

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

题意:a个红球,b个蓝球,放进n个桶里,桶可控,球可剩,问有多少种情况

思路:

红蓝两色分开讨论,然后相乘即可。对于每种颜色球,若有m个,我们分别讨论放0->m个球。这里就是一个隔板法
x 1 x_1 x1 + x 2 x_2 x2 + …+ x n x_n xn = 0 => 就1种情况
x 1 x_1 x1 + x 2 x_2 x2 + …+ x n x_n xn = 1 => 1-1个间隙 + n个可空位隔板=> C n + 1 − 1 1 C{^1_{n+1-1}} Cn+111
x 1 x_1 x1 + x 2 x_2 x2 + …+ x n x_n xn = 2=> 2-1个间隙 + n个可空位隔板=> C n + 2 − 1 1 C{^1_{n+2-1}} Cn+211
x 1 x_1 x1 + x 2 x_2 x2 + …+ x n x_n xn = 3=> 3-1个间隙 + n个可空位隔板=> C n + 3 − 1 1 C{^1_{n+3-1}} Cn+311

所以就累加1->m的情况数即可。
两个球情况累乘即是题要求输出。

AC代码:

#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(long long i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline int read(){ int f = 1; int x = 0;char ch = getchar();while(ch>'9'|ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0',  ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };

ll ans = 1;
ll a, b, n;
ll ans1 = 1;

int main()
{
    while(cin>>n>>a>>b)
    {
        ll cur = 1;
        ans = 1; ans1 = 1;
        ll to = max(a,b);
        rep(i,1,to)
        {
            cur=cur*(n-1+i)/i;
            ans1 +=cur ;
            if(i==a) ans*=ans1;
            if(i==b) ans*=ans1;
        }
        printf("%I64u\n", ans);
    }

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值