zoukankan      html  css  js  c++  java
  • 1236B

    传送门
    思路:

    可以把n件物品拆成一件一件来考虑;

    对于每一件物品,要保证至少有一个是放在m个包中的某一个包里的,那么总的合法方案就是 2^m-1(对于每一个包放或者不放,最后减去全不放的情况);

    那么总的答案 就是第一种的物品的方案 * 第二种物品的方案 * …… =(2^m-1) ^ n ;(要把每一种物品放置 组合成 n 种物品放置);

    同时这种考虑方法也规避掉了一个包 放置多个同一种物品的情况;

    AC代码

    #include<cstdio>
    #include<cstring>
    #include<cctype>
    #include<algorithm>
    using namespace std;
    typedef long long LL;
    const int N=1e6+5;
    const int inf=0x3f3f3f3f;
    const int mod=1e9+7;
    #define ls (i<<1)
    #define rs (i<<1|1)
    #define fi first
    #define se second
    #define mk make_pair
    #define mem(a,b) memset(a,b,sizeof(a))
    LL read()
    {
        LL x=0,t=1;
        char ch;
        while(!isdigit(ch=getchar())) if(ch=='-') t=-1;
        while(isdigit(ch)){ x=10*x+ch-'0'; ch=getchar(); }
        return x*t;
    }
    LL fp(LL x,LL y)
    {
        LL res=1;
        while(y)
        {
            if(y&1) res=res*x%mod;
            x=x*x%mod;
            y>>=1;
        }
        return res;
    }
    int main()
    {
        LL n=read(),m=read();
        LL tmp=fp(2,m)-1;
        printf("%lld
    ",fp(tmp,n) );
        return 0;
    }
    
  • 相关阅读:
    HashMap实现原理
    框架-Spring
    团队开发介绍
    返回一个环状整数数组中最大子数组之和
    软件工程学习体会
    书店促销
    寻找小水王
    梦断代码阅读笔记3
    找水王
    梦断代码阅读笔记2
  • 原文地址:https://www.cnblogs.com/DeepJay/p/12025186.html
Copyright © 2011-2022 走看看