• [Jsoi2011]分特产(容斥原理+组合数学)


    Description

    JYY 带队参加了若干场ACM/ICPC 比赛,带回了许多土特产,要分给实验室的同学们。
    JYY 想知道,把这些特产分给N 个同学,一共有多少种不同的分法?当然,JYY 不希望任
    何一个同学因为没有拿到特产而感到失落,所以每个同学都必须至少分得一个特产。
    例如,JYY 带来了2 袋麻花和1 袋包子,分给A 和B 两位同学,那么共有4 种不同的
    分配方法:
    A:麻花,B:麻花、包子
    A:麻花、麻花,B:包子
    A:包子,B:麻花、麻花
    A:麻花、包子,B:麻花

    Input

    输入数据第一行是同学的数量N 和特产的数量M。
    第二行包含M 个整数,表示每一种特产的数量。
    N, M 不超过1000,每一种特产的数量不超过1000

    Output

    输出一行,不同分配方案的总数。由于输出结果可能非常巨大,你只需要输出最终结果
    MOD 1,000,000,007 的数值就可以了。

    Sample Input

    5 4
    1 3 3 5

    Sample Output

    384835






     

    每个人都有=总方案数-至少有一个同学没有+至少两个同学没有-.......






     1 #include <cstdio>
     2 #include <cstdlib>
     3 #include <algorithm>
     4 #include <string>
     5 #define mod 1000000007
     6 #define LL long long
     7 using namespace std;
     8 int c[2005][2005];
     9 int a[2005];
    10  
    11 int main()
    12 {
    13     //freopen("ztest.txt","r",stdin);
    14     int n, m;
    15     LL ans = 0;
    16     for (int i=0;i<=2000;++i) c[i][0]=1;
    17     for (int i=1;i<=2000;++i)
    18         for (int j=1;j<=2000;++j)
    19             c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
    20     scanf("%d%d", &n, &m);
    21     for(int i = 1; i <= m; i++)
    22         scanf("%d", &a[i]);
    23     for (int i=0, f=1; i<=n; ++i, f=-f)
    24     {
    25         LL now = 1;
    26         for (int j = 1; j <= m; ++j)
    27             now = now * c[a[j]+n-i-1][n-i-1] % mod;
    28         ans = (ans + now * c[n][i] % mod * f) % mod;
    29     }
    30     ans = ( ans % mod + mod) % mod;
    31     printf("%lld
    ",ans);
    32     return 0;
    33 }
    34     
     
     
     
     
     
     
     
     
     
     
  • 相关阅读:
    Tips for C++ Primer Chapter 11 关联容器
    Tips for C++ Primer Chapter 10 泛型算法
    Tips for C++ Primer Chapter 9 顺序容器
    Tips for C++ Primer Chapter 8 IO库
    Trie Tree 字典树
    Manacher Algorithm 最长回文子串
    【Android Studio】android Internal HTTP server disabled 解决
    释放修改OS X 10.11系统文件权限【转】
    win10 Vmware12装mac os X10.11虚拟机教程
    【Android开发实践】android.view.InflateException: Binary XML file line #12: Error inflating class fragment问题解决
  • 原文地址:https://www.cnblogs.com/zhangbuang/p/10982154.html
Copyright © 2020-2023  润新知