zoukankan      html  css  js  c++  java
  • bzoj4710 分特产

    嘟嘟嘟


    因为刚刚做过一道类似的,所以感觉容斥可做。


    但自己还是没有搞出来,容斥这方面没做多少题果然是硬伤。
    对于每一种特产都用插板法算出分配方案,然后乘起来就是有人可能啥都没得到的方案数,即(prod C_{n + a_i + 1} ^ {n - 1})
    这时候用容斥,减去至少有一个人什么都没有,加上至少有两个人什么都没有,减去三个人……然后就没了。

    #include<cstdio>
    #include<iostream>
    #include<cmath>
    #include<algorithm>
    #include<cstring>
    #include<cstdlib>
    #include<cctype>
    #include<vector>
    #include<stack>
    #include<queue>
    #include<assert.h>
    using namespace std;
    #define enter puts("") 
    #define space putchar(' ')
    #define Mem(a, x) memset(a, x, sizeof(a))
    #define In inline
    typedef long long ll;
    typedef double db;
    const int INF = 0x3f3f3f3f;
    const db eps = 1e-8;
    const int maxn = 2e3 + 5;
    const ll mod = 1e9 + 7;
    In ll read()
    {
      ll ans = 0;
      char ch = getchar(), last = ' ';
      while(!isdigit(ch)) last = ch, ch = getchar();
      while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
      if(last == '-') ans = -ans;
      return ans;
    }
    In void write(ll x)
    {
      if(x < 0) x = -x, putchar('-');
      if(x >= 10) write(x / 10);
      putchar(x % 10 + '0');
    }
    In void MYFILE()
    {
    #ifndef mrclr
      freopen(".in", "r", stdin);
      freopen(".out", "w", stdout);
    #endif
    }
    
    int n, m, a[maxn];
    
    ll fac[maxn], inv[maxn];
    In ll inc(ll a, ll b) {return a + b < mod ? a + b : a + b - mod;}
    In ll C(int n, int m) {return fac[n] * inv[m] % mod * inv[n - m] % mod;}
    In ll quickpow(ll a, ll b)
    {
      ll ret = 1;
      for(; b; b >>= 1, a = a * a % mod)
        if(b & 1) ret = ret * a % mod;
      return ret;
    }
    
    In void init()
    {
      fac[0] = inv[0] = 1;
      for(int i = 1; i < maxn; ++i) fac[i] = fac[i - 1] * i % mod;
      inv[maxn - 1] = quickpow(fac[maxn -  1], mod - 2);
      for(int i = maxn - 2; i; --i) inv[i] = inv[i + 1] * (i + 1) % mod;
    }
    
    int main()
    {
      //MYFILE();
      n = read(), m = read();
      for(int i = 1; i <= m; ++i) a[i] = read();
      init();
      ll ans = 0;
      for(int i = n; i >= 0; --i)
        {
          ll tp = C(n, n - i);
          for(int j = 1; j <= m; ++j) tp = tp * C(i + a[j] - 1, i - 1) % mod;
          ans = inc(ans, ((n - i) & 1) ? mod - tp : tp);
        }
      write(ans), enter;
      return 0;
    }
    
  • 相关阅读:
    使用Aspose.Cell控件实现Excel高难度报表的生成(三)
    使用Aspose.Cell控件实现Excel高难度报表的生成(二)
    使用Aspose.Cell控件实现Excel高难度报表的生成(一)
    利用Aspose.Word控件和Aspose.Cell控件,实现Word文档和Excel文档的模板化导出
    新中新身份证阅读器不显示图片
    spring security 3 自定义认证,授权示例
    Spring Security教程
    Spring Security3实现,权限动态获取
    mybatis 做 insert操作的时候返回插入的那条数据的id
    如何在spring中获取request对象
  • 原文地址:https://www.cnblogs.com/mrclr/p/10931361.html
Copyright © 2011-2022 走看看