zoukankan      html  css  js  c++  java
  • A

    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 (1n,m1091≤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+7;
    ll ac(ll a,ll b)
    {
        ll r=1;
        while(b)
        {
            if(b%2)
                r=(a*r)%inf;
            a=(a*a)%inf;
            b=b/2;
        }
        return r;
    }
    int main()
    {
        ll n,m;
        while(cin>>n>>m)
        {
            ll k=ac(2,m)-1;
            cout<<ac(k,n)<<endl;
        }
        return 0;
    }
  • 相关阅读:
    SVN被锁定解决办法
    onchange监听input值变化及input隐藏后change事件不触发的原因与解决方法(设置readonly后onchange不起作用的解决方案)
    button的格式的问题
    javaScript年份下拉列表框内容为当前年份及前后50年
    ORACLE导入、导出所有数据到文件的SQL语句
    Oracle存储过程学习笔记
    SQlServer的日期相减(间隔)datediff函数
    td中嵌套table,让table完全填充父元素td
    Cause: org.apache.ibatis.executor.ExecutorException: Error getting generated key or setting result to parameter object. Cause: java.sql.SQLException: 不支持的特性
    HTML认知
  • 原文地址:https://www.cnblogs.com/liyexin/p/11703877.html
Copyright © 2011-2022 走看看