zoukankan      html  css  js  c++  java
  • CodeForces

    题意

    n种物品和m个背包,每种物品有无限个,现将若干个物品放到这些背包中,满足:

    1、每个背包里不能出现相同种类的物品(允许有空背包);

    2、在所有的m个背包中,每种物品都出现过。

    求方案数,对10^9+7取模。

    思路

    考虑每个物品在每个背包是否出现,那么对于物品i,有2^m中方案,然后因为在所有背包中每种物品至少要出现一次,所以要减去全不出现的方案,所以是2^m - 1,有n个物品,那么就是(2^m -1)^n

    代码

    #include<bits/stdc++.h>
    using namespace std;
    #define inf 0x3f3f3f3f
    #define ll long long
    const int N=200005;
    const int mod=1e9+7;
    const double eps=1e-8;
    const double PI = acos(-1.0);
    #define lowbit(x) (x&(-x))
    ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
    ll qpow(ll a,ll b){ll res=1;while(b){if(b&1) res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
    ll inv(ll a,ll p){return qpow(a,p-2);}
    int main()
    {
        std::ios::sync_with_stdio(false);
        ll n,m;
        cin>>n>>m;
        cout<<qpow((qpow(2,m)-1+mod)%mod,n)<<endl;
        return 0;
    }
    

      

  • 相关阅读:
    异或运算
    GitHub使用简介
    归并排序
    快速排序
    字符串匹配
    Runner站立会议06
    Runner站立会议05
    Runner站立会议04
    记计账需求分析
    Runner站立会议03
  • 原文地址:https://www.cnblogs.com/mcq1999/p/11906527.html
Copyright © 2011-2022 走看看