• 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;
    }
    
  • 相关阅读:
    C# 设计模式-桥接模式
    C# 设计模式-外观模式
    C# 设计模式-代理模式
    楼层导航奇葩问题解决
    楼层导航和回顶部
    回顾
    禁止右击选中
    安装客服在线系统
    csdn 分享私藏的18个黑科技网站,想找什么软件就找什么软件!!!
    eyoucms 模板
  • 原文地址:https://www.cnblogs.com/DeepJay/p/12025186.html
Copyright © 2020-2023  润新知