CodeForces - 1236B (简单组合数学)
题意
有n种物品和m个背包,每种物品有无限个,现将若干个物品放到这些背包中,满足:
1、每个背包里不能出现相同种类的物品(允许有空背包);
2、在所有的m个背包中,每种物品都出现过。
求方案数,对10^9+7取模。
思路
考虑每个物品在每个背包是否出现,那么对于物品i,有2^m中方案,然后因为在所有背包中每种物品至少要出现一次,所以要减去全不出现的方案,所以是2^m - 1,有n个物品,那么就是(2^m -1)^n
代码
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N=200005;
const int mod=1e9+7;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
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;}
ll inv(ll a,ll p){return qpow(a,p-2);}
int main()
{
std::ios::sync_with_stdio(false);
ll n,m;
cin>>n>>m;
cout<<qpow((qpow(2,m)-1+mod)%mod,n)<<endl;
return 0;
}
CodeForces - 1236B (简单组合数学)的更多相关文章
- Codeforces 15E Triangles - 组合数学
Last summer Peter was at his granny's in the country, when a wolf attacked sheep in the nearby fores ...
- Colorful Bricks CodeForces - 1081C ( 组合数学 或 DP )
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in t ...
- You Are Given a Decimal String... CodeForces - 1202B [简单dp][补题]
补一下codeforces前天教育场的题.当时只A了一道题. 大致题意: 定义一个x - y - counter :是一个加法计数器.初始值为0,之后可以任意选择+x或者+y而我们由每次累加结果的最后 ...
- Mysterious Crime CodeForces - 1043D (思维+组合数学)
Acingel is a small town. There was only one doctor here — Miss Ada. She was very friendly and nobody ...
- Codeforces 935 简单几何求圆心 DP快速幂求与逆元
A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #def ...
- 【BZOJ1008】1008: [HNOI2008]越狱 简单组合数学+快速幂
Description 监狱有连续编号为1...N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰其中一种.如果相邻房间的犯人的宗教相同,就可能发生越狱,求有多少种状态可能发生越狱 In ...
- Paths on a Grid(简单组合数学)
Paths on a Grid Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 23008 Accepted: 5683 Desc ...
- codeforces 630H (组合数学)
H - Benches Time Limit:500MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit S ...
- BZOJ_1008_[HNOI2008]_越狱_(简单组合数学+快速幂)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1008 监狱有连续编号为1...N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰 ...
随机推荐
- Flutter学习一
包管理 依赖本地包 dependencies: pkg1: path: ../../code/pkg1 依赖git包 dependencies: pkg1: git: url: git://githu ...
- Data Management Technology(5) -- Recovery
Recovery Types of Failures Wrong data entry Prevent by having constraints in the database Fix with d ...
- Access denied for user 'root@localhost' (using password:NO)问题的解决
错误详情: 使用pymysql连接数据库mysql,一直无法连接上, conn = pymysql.connect(host='localhost', port=3306, user='root', ...
- 【tf.keras】ssl.SSLError: [SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:1977)
问题描述 tf.keras 在加载 cifar10 数据时报错,ssl.SSLError: [SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption ...
- Leetcode 1239. 串联字符串的最大长度
地址 https://leetcode-cn.com/problems/maximum-length-of-a-concatenated-string-with-unique-characters/s ...
- 05_javaSE面试题:成员变量和局部变量
题目 /** * 类变量:static修饰的 * 实例变量:不是static修饰的 * * 局部变量:栈 * 实例变量:堆 * 类变量:方法区 * @author kevin * @date 2019 ...
- BZOJ1369/LG4395 「BOI2003」Gem 树形DP
问题描述 LG4395 BZOJ1369 题解 发现对于结点 \(x\) ,其父亲,自己,和所有的孩子权值不同,共 \(3\) 类,从贪心的角度考虑,肯定是填 \(1,2,3\) 这三种. 于是套路树 ...
- Go package: strings
Go strings Go 的 strings 包中包含许多处理字符串的函数 官方文档:https://golang.org/pkg/strings/ 前缀.后缀 判断字符串前缀.后缀 // 判断字符 ...
- vue表格合并行的一个实例
一.element控件实现 在平常的应用中,需要用到合并单元格的操作,在Excel中,这种操作很好实现,但在实际项目中,常常需要借助element控件来实现. 下面是element中的一个实例 ...
- vs2010,vs2013,vs2015,vs2017, vs2019激活秘钥
vs2010============================================== YCFHQ9DWCYDKV88T2TMHG7BHP vs2013=============== ...