https://codeforces.com/contest/1236/problem/B

Alice got many presents these days. So she decided to pack them into boxes and send them to her friends.

There are nn kinds of presents. Presents of one kind are identical (i.e. there is no way to distinguish two gifts of the same kind). Presents of different kinds are different (i.e. that is, two gifts of different kinds are distinguishable). The number of presents of each kind, that Alice has is very big, so we can consider Alice has an infinite number of gifts of each kind.

Also, there are mm boxes. All of them are for different people, so they are pairwise distinct (consider that the names of mm friends are written on the boxes). For example, putting the first kind of present into the first box but not into the second box, is different from putting the first kind of present into the second box but not into the first box.

Alice wants to pack presents with the following rules:

  • She won't pack more than one present of each kind into the same box, so each box should contain presents of different kinds (i.e. each box contains a subset of nn kinds, empty boxes are allowed);
  • For each kind at least one present should be packed into some box.

Now Alice wants to know how many different ways to pack the presents exists. Please, help her and calculate this number. Since the answer can be huge, output it by modulo 109+7109+7.

See examples and their notes for clarification.

Input

The first line contains two integers nn and mm, separated by spaces (1≤n,m≤1091≤n,m≤109) — the number of kinds of presents and the number of boxes that Alice has.

Output

Print one integer  — the number of ways to pack the presents with Alice's rules, calculated by modulo 109+7109+7

Examples

Input
1 3
Output
7
Input
2 2
Output
9

Note

In the first example, there are seven ways to pack presents:

{1}{}{}{1}{}{}

{}{1}{}{}{1}{}

{}{}{1}{}{}{1}

{1}{1}{}{1}{1}{}

{}{1}{1}{}{1}{1}

{1}{}{1}{1}{}{1}

{1}{1}{1}{1}{1}{1}

In the second example there are nine ways to pack presents:

{}{1,2}{}{1,2}

{1}{2}{1}{2}

{1}{1,2}{1}{1,2}

{2}{1}{2}{1}

{2}{1,2}{2}{1,2}

{1,2}{}{1,2}{}

{1,2}{1}{1,2}{1}

{1,2}{2}{1,2}{2}

{1,2}{1,2}{1,2}{1,2}

For example, the way {2}{2}{2}{2} is wrong, because presents of the first kind should be used in the least one box.

      就是说n种礼物,放进m个互不相同的箱子里。礼物数无限。随便放,但是需要保证每种礼物都至少出现一次,而且同一种不能出现在同一个箱子里。可以出现空箱子。题意就是如此,无奈自己太笨,推了好长时间,写了各种排列组合里的C啊,A啊的。其实出发点就错了,我们把从每单个种类的礼物拿出来看,对于一种礼物A的放法:对于每一种箱子只有两种情况,A存在或者不存在,那么m个箱子就有2^m种。但是题目说箱子不能全空,那么是2^m-1种。这样保证了每一种礼物必然出现,不用担心样例2那种 {2}{2}{2}{2} 情况了。总的公式就是(2^m-1)^n。套个快速幂取模模板就可以了。

  

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const long long inf=1e9+;
ll ac(ll a,ll b)
{
ll r=;
while(b)
{
if(b%)
r=(a*r)%inf;
a=(a*a)%inf;
b=b/;
}
return r;
}
int main()
{
ll n,m;
while(cin>>n>>m)
{
ll k=ac(,m)-;
cout<<ac(k,n)<<endl;
}
return ;
}

A - Alice and the List of Presents (排列组合+快速幂取模)的更多相关文章

  1. BZOJ 1008 [HNOI2008]越狱 (简单排列组合 + 快速幂)

    1008: [HNOI2008]越狱 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 10503  Solved: 4558[Submit][Status ...

  2. 学习sql中的排列组合,在园子里搜着看于是。。。

    学习sql中的排列组合,在园子里搜着看,看到篇文章,于是自己(新手)用了最最原始的sql去写出来: --需求----B, C, F, M and S住在一座房子的不同楼层.--B 不住顶层.C 不住底 ...

  3. .NET平台开源项目速览(11)KwCombinatorics排列组合使用案例(1)

    今年上半年,我在KwCombinatorics系列文章中,重点介绍了KwCombinatorics组件的使用情况,其实这个组件我5年前就开始用了,非常方便,麻雀虽小五脏俱全.所以一直非常喜欢,才写了几 ...

  4. 【原创】开源.NET排列组合组件KwCombinatorics使用(三)——笛卡尔积组合

           本博客所有文章分类的总目录:本博客博文总目录-实时更新 本博客其他.NET开源项目文章目录:[目录]本博客其他.NET开源项目文章目录 KwCombinatorics组件文章目录: 1. ...

  5. 【原创】开源.NET排列组合组件KwCombinatorics使用(二)——排列生成

           本博客所有文章分类的总目录:本博客博文总目录-实时更新 本博客其他.NET开源项目文章目录:[目录]本博客其他.NET开源项目文章目录 KwCombinatorics组件文章目录: 1. ...

  6. 【原创】开源.NET排列组合组件KwCombinatorics使用(一)—组合生成

           本博客所有文章分类的总目录:本博客博文总目录-实时更新 本博客其他.NET开源项目文章目录:[目录]本博客其他.NET开源项目文章目录 KwCombinatorics组件文章目录: 1. ...

  7. hdu1521 排列组合(指数型母函数)

    题意: 有n种物品,并且知道每种物品的数量ki.要求从中选出m件物品的排数.         (全题文末) 知识点: 普通母函数 指数型母函数:(用来求解多重集的排列问题) n个元素,其中a1,a2, ...

  8. [leetcode] 题型整理之排列组合

    一般用dfs来做 最简单的一种: 17. Letter Combinations of a Phone Number Given a digit string, return all possible ...

  9. 排列组合算法(PHP)

    用php实现的排列组合算法.使用递归算法,效率低,胜在简单易懂.可对付元素不多的情况. //从$input数组中取$m个数的组合算法 function comb($input, $m) { if($m ...

随机推荐

  1. 腾讯X5内核使用详解(X5内核播放器使用如何去除控制栏全屏播放)以及一些注意事项

    例子下载地址 https://www.lanzous.com/i2zsv5g      GIT就不用了麻烦的不行 本人安卓刚学 就上X5内核弄了老长时间由于对maven 和idea不熟悉刚开始导包都是 ...

  2. 电脑必须用U盘引导盘才能进系统解决办法

    昨天为了装Ubuntu双系统把系统给装崩了,结果重装win7系统之后出现了以下问题,百度的结果有些杂乱,解决过程自己做一下记录. 问题一:安装程序结束后,出现“Windows安装程序无法将Window ...

  3. redis的配置文件介绍

    目录 1.开头说明 2.INCLUDES 3.MODULES 4.NETWORK 5.GENERAL 6.SNAPSHOTTING 7.REPLICATION 8.SECURITY 9.CLIENTS ...

  4. 记一次docker使用异常

    背景: win10 docker 有几天没有用Oracle数据库,突然发现数据库挂了 docker start oracle 报错 具体错误信息: Error starting userland pr ...

  5. 九十、SAP中ALV事件之四,事件子例程的参数

    一.我们按照之前SAP说明里面的文字,定义好相关内容 二.上图代码对应的文档错了,重现截图一下 三.这3个子例程是不需要写调用语句PERFORM的,在SAP内部已经写好了.程序会自动根据名字找到需要调 ...

  6. 简述哲学Essay写作

    哲学类essay写作对于中国留学生来说算是比较难的作业了,它不仅有结构要求,还注重逻辑的紧密性.很多同学都不知道该怎么下手.今天小编就给同学们分享哲学essay写作的结构.同学们可以尝试按照以下方法来 ...

  7. 实验吧-杂项-flag.xls(notepad++查找)、保险箱(linux文件分解、密码破解)

    flag.xls 下载文件,用notepad++打开,查找flag就能找到flag. 保险箱(linux文件分解.密码破解) 将图片保存下来,用kali的binwalk分析,发现有rar文件,然后用f ...

  8. 十三、react-router 4.x的基本配置

    路由的定义及作用 根组件根据客户端不同的请求网址显示时,要卸载上一个组件,再挂载下一个组件,如果手动操作话将是一个巨大麻烦.具体过程如下图: [根组件] ↑ [首页组件] [新闻组件] [商品组件] ...

  9. 前端基础之Html、CSS

    Html.css相关 Html Html结构: 标签 描述 <!DOCTYPE html> 文档声明 <html> 根元素 <head> 头部 <body 主 ...

  10. html 基础 (9.19 第八天)

    一.HTML:超文本标记语言,是一种标签语言,不是编程语言,显示数据有双标签<body></body> 和单标签<img src=# / >, 标签大小写都可以通过 ...