Codeforces - 1236B Alice and the List of Presents(思维)

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

题意:给你n种礼物和m个盒子,每个礼物有无限个。
现在要将礼物放进盒子里,遵循以下规则:
(1)每个盒子里每种礼物最多只有一个,盒子可以为空;
(2)每种礼物至少放一个。
问一共有多少中方案数,答案对1e9 + 7取模。

思路:
(1)考虑一种礼物,m个盒子的情况(样例一),那样每个盒子要么放一个礼物,要么不放,再减去所有盒子全部为空的情况,一共有2^m - 1种情况;
(2)考虑n种礼物,m个盒子的情况,每个礼物之间都是相互独立的,所以答案便是(2^m - 1) ^ n;
所以答案便是(2^m - 1) ^ n,跑个快速幂就好。

代码:

#include <queue>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long

const int maxn = 1e3+ 7;
const int IMAX = 2e4 + 7;
const int mod = 1e9 + 7;

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;
}

int main() {
    LL n , m;
    while(~scanf("%lld%lld",&n,&m)) {
        printf("%lld\n",qpow(qpow(2LL,m) - 1LL , n));
    }
    return 0;
}

 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值