CF1236B Alice and the List of Presents
题意翻译
有nn种物品和mm个背包,每种物品有无限个,现将若干个物品放到这些背包中,满足:
1、每个背包里不能出现相同种类的物品(允许有空背包);
2、在所有的mm个背包中,每种物品都出现过。
求方案数,对10^9+7取模。
转载至 风华正茂
这不是一道水题吗?
尽管比赛时推了20min,我太蒟了。
假如这道题目没有“每种物品都出现过”的限制,那么它的答案就是 2^nm
那么加上这个限制呢,每种物品必须要放,只用将每种物品的方案减一即可,也就是 2^m-1
所以用乘法原则得到 ans=(2m-1)n
快速幂都会吧
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int mod=1e9+7;
#define int long long
int n,m;
inline int ksm(int x,int y){
int ans=1;
while(y){
if(y&1)ans=(ans*x)%mod;
x=x*x%mod;
y>>=1;
}
return ans;
}
signed main(){
cin>>n>>m;
printf("%lld\n",ksm(ksm(2,m)-1,n));
}
CF1236B Alice and the List of Presents的更多相关文章
- A - Alice and the List of Presents (排列组合+快速幂取模)
https://codeforces.com/contest/1236/problem/B Alice got many presents these days. So she decided to ...
- Codeforces 1236B. Alice and the List of Presents
传送门 显然每种礼物是互相独立的,一个礼物的分配不会影响另一个礼物 对于某个礼物 $x$ , 对于每个盒子来说,要么选要么不选,那么可以看成长度为 $m$ 的二进制序列 这个序列第 $i$ 位的数就代 ...
- Codeforces Round #593 (Div. 2)
传送门 A. Stones 签到. B. Alice and the List of Presents 单独考虑每个数的贡献即可. 答案为\((2^{m}-1)^n\). C. Labs 构造就类似于 ...
- (HDU 5558) 2015ACM/ICPC亚洲区合肥站---Alice's Classified Message(后缀数组)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5558 Problem Description Alice wants to send a classi ...
- 2016中国大学生程序设计竞赛 - 网络选拔赛 J. Alice and Bob
Alice and Bob Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- bzoj4730: Alice和Bob又在玩游戏
Description Alice和Bob在玩游戏.有n个节点,m条边(0<=m<=n-1),构成若干棵有根树,每棵树的根节点是该连通块内编号最 小的点.Alice和Bob轮流操作,每回合 ...
- Alice and Bob(2013年山东省第四届ACM大学生程序设计竞赛)
Alice and Bob Time Limit: 1000ms Memory limit: 65536K 题目描述 Alice and Bob like playing games very m ...
- 阿里前端框架Alice是个不错的选择
BootStrap虽然用户群体广大,其整体风格尽管有不少skin可选,但以国情来看还是不好看. 阿里开源的前端框架,个人觉得还是很不错,Alice处处透着支付宝中界面风格的气息,电商感挺强. 以下内容 ...
- poj 1698 Alice‘s Chance
poj 1698 Alice's Chance 题目地址: http://poj.org/problem?id=1698 题意: 演员Alice ,面对n场电影,每场电影拍摄持续w周,每周特定几天拍 ...
随机推荐
- PTA刷题记录(3)
团队天梯赛-------(3)分值:15 给定一个 k 位整数 N=dk−110k−1+⋯+d1101+d0 (0≤di≤9, i=0,⋯,k−1, dk−1 ...
- 2019年10月11号 王庆超 linux
1.计算机操作系统简介 (1)掌握操作系统的定义:操作系统是一个用来协调.管理和控制计算机硬件和软件资源的系统 程序,它位于硬件和应用程序之间. (2)掌握操作系统的内核的定义:操作系统的内核是一个管 ...
- day8-函数
---def test(x): # def:定义函数的关键字,test:函数名, x相当于以前函数中的自变量使用函数的好处:1.代码重用2.保持一致性,易于维护3.可扩展性 def test(x): ...
- tornado的使用-参数篇
tornado的使用-参数篇
- nyoj 412 Same binary weight ()
Same binary weight 时间限制:300 ms | 内存限制:65535 KB 难度:3 描述 The binary weight of a positive integer ...
- pat 1120 Friend Numbers(20 分)
1120 Friend Numbers(20 分) Two integers are called "friend numbers" if they share the same ...
- nyoj 113-字符串替换 (python replace, try ... except)
113-字符串替换 内存限制:64MB 时间限制:3000ms 特判: No 通过数:31 提交数:71 难度:2 题目描述: 编写一个程序实现将字符串中的所有"you"替换成&q ...
- 队列+BFS(附vector初试)
优先队列的使用: include<queue>//关联头文件 struct node{ int x,y; friend bool operator < (node d1,node d ...
- Nethunter开启ssh服务
### 本节用来纪念我和我的Nethunter SSH服务的血泪史 刚安装好Nethunter后,手机的各种功能也是令我眼花缭乱,对手机是爱不释手,可是,手机开启ssh服务之后,电脑无法连接,这就很尴 ...
- [apue] 神奇的 Solaris pipe
说到 pipe 大家可能都不陌生,经典的pipe调用配合fork进行父子进程通讯,简直就是Unix程序的标配. 然而Solaris上的pipe却和Solaris一样是个奇葩(虽然Solaris前途黯淡 ...