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;
    }
  • 相关阅读:
    Smarty简单配置代码
    5.27权限练习
    PHP函数中的变量
    PHP文件格式数组
    PHP文件操作
    MongoCola MongoDB 客户端管理工具
    使用NPOI库导入导出EXCEL
    MVC Filter使用
    MVC设计及使用拓展
    C# 基础·语法篇
  • 原文地址:https://www.cnblogs.com/dealer/p/13053827.html
Copyright © 2011-2022 走看看