Safety system (Yang Hui triangle to find the combination number)

Title Portal

The title is
to give you n boxes. You can put 0 or 1 in each box, you can put only one, you can put them all, you can put none at all, there are now a 1, b 0, each 1 or each 0 Not the same, ask how many options you have to put.

Data range
a, b≤50, n + a \ le 50n + a≤50, n + b \ le 50n + b≤50

Idea
Note that each 1 (or 0) is different, this stuck me for a long time. , This problem is easy to think of the solution of combinatorial mathematics. Because they do not affect each other, we can put 1 first and then 0. For putting 1, we can choose i 1 out of a 1 and then choose 1 out of n positions to put 1, which is equivalent to C n i * C a i , the same is true for 0. Finally, multiply the number of solutions put by 1 and the number of solutions put by 0.

But if we use factorial to calculate the combined number according to the formula, the accuracy will be exploded, so we have to find another way.
I wrote a question about Yang Hui's triangle to find the combination number before, which can be used here. Open data ULL .

#include<bits/stdc++.h>
using namespace std;
const int N=1e3+5;
const int inf=0x7fffffff;
const int mod=1e9+7;
const int eps=1e-6;
typedef long long ll;
typedef unsigned long long ull;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
ull c[N][N];
void zuhe()
{
    c[0][0]=1;
    for(int i=1;i<=55;i++)
    {
        for(int j=0;j<=i;j++)
        {
            c[i][j]=c[i-1][j];
            if(j!=0)
                c[i][j]+=c[i-1][j-1];
        }
    }
}
signed main()
{
    IOS;
    int n,a,b;
    cin>>n>>a>>b;
    zuhe();
    ull res=0;
    ull tt=0;
    for(int i=0;i<=min(a,n);i++)
    {
        tt+=c[n][i]*c[a][i];
    }
    res=tt;tt=0;
    for(int i=0;i<=min(b,n);i++)
    {
        tt+=c[n][i]*c[b][i];
    }
    res*=tt;
    cout<<res<<endl;
}

Published 93 original articles · won praise 9 · views 4203

Guess you like

Origin blog.csdn.net/Joker_He/article/details/104851838