• B. Alice and the List of Presents


    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
    Copy
    1 3
    
    output
    Copy
    7
    input
    Copy
    2 2
    
    output
    Copy
    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.

    考虑把每种礼物放进不同的盒子

    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <set>
    #include <queue>
    #include <map>
    #include <sstream>
    #include <cstdio>
    #include <cstring>
    #include <numeric>
    #include <cmath>
    #include <iomanip>
    #include <deque>
    #include <bitset>
    #include <unordered_set>
    #include <unordered_map>
    #define ll              long long
    #define PII             pair<int, int>
    #define rep(i,a,b)      for(int  i=a;i<=b;i++)
    #define dec(i,a,b)      for(int  i=a;i>=b;i--)
    using namespace std;
    int dir[4][2] = { { 0,1 } ,{ 0,-1 },{ 1,0 },{ -1,0 } };
    const long long INF = 0x7f7f7f7f7f7f7f7f;
    const int inf = 0x3f3f3f3f;
    const double pi = 3.14159265358979323846;
    const double eps = 1e-6;
    const int mod =1e9+7;
    const int N = 100005;
    //if(x<0 || x>=r || y<0 || y>=c)
    
    inline ll read()
    {
        ll x = 0; bool f = true; char c = getchar();
        while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); }
        while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
        return f ? x : -x;
    }
    ll gcd(ll m, ll n)
    {
        return n == 0 ? m : gcd(n, m % n);
    }
    ll lcm(ll m, ll n)
    {
        return m * n / gcd(m, n);
    }
    ll qpow(ll m, ll k, ll mod)
    {
        ll res = 1, t = m;
        while (k)
        {
            if (k & 1)
                res = res * t % mod;
            t = t * t % mod;
            k >>= 1;
        }
        return res;
    }
    ll n, m;
    int main()
    {
        cin >> n >> m;
        int res = qpow(2, m,mod) - 1;
        int ans = qpow(res, n, mod);
        cout << ans << endl;
        return 0;
    }
  • 相关阅读:
    vue 组件的简单使用01
    vue 绑定 class 和 内联样式(style)
    input select 值得绑定与获取
    computed 计算属性
    v-for 循环 绑定对象 和数组
    过滤器 filter
    v-model 双向数据绑定以及修饰符
    v-on 绑定单个或多个事件
    v-bin:href 绑定链接
    .net core自动发送后台请求写法
  • 原文地址:https://www.cnblogs.com/dealer/p/13053827.html
Copyright © 2020-2023  润新知