OI

题解Codeforces1236B

题解

Posted by chicken2011 on April 4, 2023

题目传送门

解析

每一种物品都有放进去和不放进去两种选择,但是不能全部不放,也就是说要减去不放的情况。所以共有 $ 2^m-1 $ 种情况,一共有 $n$ 种物品,总共就是 $ (2^m-1)^n $ 种情况。

注意点

  • 不开 long long 见祖宗。
  • 需使用快速幂。

代码

```cpp #include<bits/stdc++.h> // 万能头 using namespace std; typedef long long ll; // 需开 long long const int mod = 1000000007; // 取模值 ll n,m,ans; ll kasumi(ll a,ll b){ // 快速幂 ll ret=1; while(b){ if(b%2) ret=(reta)%mod; a=(aa)%mod; b»=1; } return ret; } int main(){ ios::sync_with_stdio(false); // 断开 cin scanf cin.tie(NULL);cout.tie(NULL); // cin cout 加速 cin » n » m; ans=kasumi(kasumi(2,m)-1+mod,n); cout « ans; return 0; // 好习惯 } ``