zoukankan      html  css  js  c++  java
  • 容斥计算多重组合

    http://oj.ecustacm.cn/problem.php?id=1253

    题意:一副扑克牌52张(除去大小王),求从中拿13张牌的组合数(只考虑点数)。

    1、解法:应用容斥原理:

    该多重集合S = {4*1 , 4*2 , 4*3 , 4*4....... 4*10 , 4*11(J), 4*12(Q) , 4*13(K)}

    定义性质集合P = {P1 , P2 , ..... P13}.Pi表示13组合中i的个数大于等于5的集合2

    可以知道全集U为13种类型对象的多重集,每种元素均有无限重复数,的13组合为C (13 + 13 - 1 , 13).

    Ã = U - (P1 + P2 + ... + P13) + (P1∩P2 + P1∩P3.....+P12∩P13).......

    先选4张i其他牌张数不限 Pi = C (8 + 13 - 1 , 8)。

    Pi ∩ Pj = C(3 + 13 - 1 , 3).

    可以知道三个集合的交集为0.

    Ã = C(13 + 13 - 1 , 13) - 13 * C(8+13-1 , 8) + C(13,2)C(3+13-1 , 3) = 3598180.

    参考博客:https://www.cnblogs.com/vectors07/p/7976446.html

    2、解法:dfs

    枚举每一种牌的数量。

    #include<bits/stdc++.h>
    using namespace std;
    int ans ;
    
    void dfs(int num , int t)
    {
        if(num == 13){//凑齐13张牌了
            ans++;
            return ;
        }
        if(t >= 13) return ;//dfs深度为13,一共13种牌
        for(int i = 0 ; i <= 4 ; i++)//枚举每一种牌的数量
            dfs(num+i , t+1);
    }
    
    int main()
    {
    
        dfs(0 , 0);
        cout << ans << endl ;
        return 0;
    }
    
  • 相关阅读:
    Java经典逻辑编程50题 (转)
    Programmingbydoing
    前端测试框架jest 简介
    puppeteer入门
    面向对象编程
    Java常识
    JS 变量
    jmeter 压力测试
    jmeter 安装
    Java 数据驱动测试
  • 原文地址:https://www.cnblogs.com/nonames/p/12248953.html
Copyright © 2011-2022 走看看