Alice and the List of Presents
题目
思路:
把n件物品拆成一件一件来考虑;
对于每一件物品,要保证至少有一个是放在m个包中的某一个包里的,那么总的合法方案就是 2^m-1(对于每一个包放或者不放,最后减去全不放的情况);
总的答案 就是第一种的物品的方案 * 第二种物品的方案 * …… =(2^m-1) ^ n ;(要把每一种物品放置 组合成 n 种物品放置);
同时这种考虑方法也规避掉了一个包 放置多个同一种物品的情况;
#include<bits/stdc++.h>
#define ll long long
using namespace std;
typedef unsigned long long ULL;
const int N=100010;
ll mod=1e9+7;
long long qPow(long long int a,long long int n){
long long int ans=1;
while(n>0){
if(n&1)//取二进制最末端
ans=(ans*a)%mod;
a=(a*a)%mod;
n>>=1;//右移一位
//将n写成二进制的形式,遇到1就与结果相乘
}
return ans;
}
int main() {
int m,n;
cin>>m>>n;
ll temp=qPow(2,n)-1;
l ans=qPow(temp,m);
cout<<ans<<endl;
return 0;
}