zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    Java相对路径读取文件
    【转载】 OpenCV ——双线性插值(Bilinear interpolation)
    【转载】 从ACM会议看中国大陆计算机科学与国外的差距
    【转载】 一个老博士的经验顺口溜! 研究生生活的精华总结!
    【转载】 研究生生活总结(2):从技术到研究再到技术的过程
    【转载】 研究生生活总结(1):当助教的那些人和事
    【转载】 如何看待 2019 年 CS PhD 现扎堆申请且大部分为 AI 方向?未来几年 AI 泡沫会破裂吗?
    【转载】 深度强化学习处理cartpole为什么reward很难超过200?
    【转载】 强化学习中 采用 【首次访问的蒙特卡洛预测法】 的算法描述
    【转载】 混合智能
  • 原文地址:https://www.cnblogs.com/dealer/p/13053827.html
Copyright © 2011-2022 走看看