zoukankan      html  css  js  c++  java
  • Codeforces 1236B. Alice and the List of Presents

    传送门

    显然每种礼物是互相独立的,一个礼物的分配不会影响另一个礼物

    对于某个礼物 $x$ , 对于每个盒子来说,要么选要么不选,那么可以看成长度为 $m$ 的二进制序列

    这个序列第 $i$ 位的数就代表第 $i$ 个盒子里是否有这个礼物,那么总方案即为 $2^m-1$ ,减 $1$ 是因为全 $0$ 的序列是不合法的

    然后根据乘法原理最终答案即为每个礼物的方案的乘积 :$(2^m-1)^n$

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<cmath>
    using namespace std;
    typedef long long ll;
    inline int read()
    {
        int x=0,f=1; char ch=getchar();
        while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
        while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
        return x*f;
    }
    const int mo=1e9+7;
    int n,m;
    inline int ksm(int x,int y)
    {
        int res=1;
        while(y) { if(y&1) res=1ll*res*x%mo; x=1ll*x*x%mo; y>>=1; }
        return res;
    }
    int main()
    {
        n=read(),m=read();
        printf("%d
    ",ksm((ksm(2,m)-1+mo)%mo,n));
        return 0;
    }
  • 相关阅读:
    Hibernate 与 mybatis 区别
    Struts2 核心流程
    java 面试 -- 4
    无线电日记 2
    ham 无线电笔记
    Our Deepest Fear
    随笔
    GSM学习笔记
    网络时代的悲哀:微软百科全书
    [转载]arm交叉编译器gnueabi、none-eabi、arm-eabi、gnueabihf、gnueabi区别
  • 原文地址:https://www.cnblogs.com/LLTYYC/p/11699228.html
Copyright © 2011-2022 走看看