zoukankan      html  css  js  c++  java
  • UPC--扑克牌

    题目描述

    从一副含有n(n≤10000)张的扑克牌[显然每张扑克牌都不相同]中,分给m(m≤100)个人,第i个人得到ai (0≤ai≤100)张牌,求一共有几种分法,这个数可能非常大,请输出此数模10007后的结果。

    输入

    第一行两个整数 为 n m
    第二行 m个整数 ai

    输出

    一个整数,表示有多少种分法

    样例输入

    【样例15 2
    3 1
    【样例220 19
    1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    

    样例输出

    【样例120
    【样例28707
    

    思路:很明显的组合数学的经典问题,可以用杨辉三角打表来处理,然后做乘法取余就完事比如第一个样例就是C(5,3)*C(2,1);
    利用for循环来解决问题

    #pragma GCC optimize (2)
    #pragma G++ optimize (2)
    #include <bits/stdc++.h>
    #include <algorithm>
    #include <map>
    #include <queue>
    #include <set>
    #include <stack>
    #include <string>
    #include <vector>
    using namespace std;
    #define wuyt main
    typedef long long ll;
    #define HEAP(...) priority_queue<__VA_ARGS__ >
    #define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
    template<class T> inline T min(T &x,const T &y){return x>y?y:x;}
    template<class T> inline T max(T &x,const T &y){return x<y?y:x;}
    //#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
    //char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
    ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();
    if(c == '-')Nig = -1,c = getchar();
    while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();
    return Nig*x;}
    #define read read()
    const ll inf = 1e15;
    const int maxn = 2e5 + 7;
    const int mod = 1e9 + 7;
    #define start int wuyt()
    #define end return 0
    ll num[10008][108]={1};
    ///
    void yanghui()
    {
        num[0][0]=1;
        for(int i=1;i<=10000;i++){
            for(int j=0;j<=100;j++){
                num[i][j]=(num[i-1][j]+num[i-1][j-1])%10007;
            }
        }
    }
    ll n,m,all=1;
    start{
        n=read,m=read;
        yanghui();
        ///cout<<num[3][2]<<endl;
        for(int i=1;i<=m;i++){
            int temp;
            scanf("%d",&temp);
            all=(all*num[n][temp])%10007;
            n-=temp;
        }
        cout<<all;
        end;
    }
    
  • 相关阅读:
    Hibernate 中出现 XXXX is not mapped 问题
    记录一下表格用poi的导出word
    [转帖] 悟透JavaScript
    JAVA读取Oracle中的blob图片字段并显示
    vs2010代码段,用得飞起~
    FontFamily获取中文名字
    vs2010快捷键
    WPF Binding基础
    Binding对数据的转换和校验
    WPF个UI元素
  • 原文地址:https://www.cnblogs.com/PushyTao/p/13144196.html
Copyright © 2011-2022 走看看