Codeforces 1236B Alice and the List of Presents(贡献)

链接:https://codeforces.com/contest/1236/problem/B

题意:n种物品(不限量),m个盒子,问有多少种合法的放置物品的方案,合法:每个盒子都可以选择任意一个或多种物品(每种最多一个)也可以不选择任意一个,当m个盒子可以包括这n个物品即可。n, m<1e9

题解:考虑每一个物品对答案的贡献,每一个物品在m个箱子都有 2*m-1种方案,总计:(2*m-1)*n

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int mod=1e9+7;
ll n, m;

ll qpow(ll a, ll b)
{
    ll base=a, res=1;
    while(b)
    {
        if(b&1) res=res*base%mod;
        base=base*base%mod;
        b>>=1;
    }
    return res;
}

int main()
{
    cin>>n>>m;
    ll ans=(qpow(2, m)+mod-1)%mod;
    ans=qpow(ans, n)%mod;
    cout<<ans;
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/Yokel062/p/11768131.html
今日推荐