zoukankan      html  css  js  c++  java
  • BZOJ4402 : Claris的剑

    考虑给定每个数字的个数,构造出这个序列:

    肯定是1 2 1 2 3 2 3 2 3 4 3 4 ... 最大值,

    或者1 2 1 2 3 2 3 2 3 4 3 4 ... 最大值 最大值-1。

    本质不同的情况只有这两种,且互相不交。

    设最大值为$m$,那么$1$到$m$都要有$1$个,剩下的数每多一个$i$,就要多一个$i+1$。

    剩下的数假设有$t$个,那么对于每种情况,等价于$lfloorfrac{t}{2} floor$个相同的球放入$m$个不同的盒子里,允许空盒的方案数,即$C(lfloorfrac{t}{2} floor+m,m)$。

    枚举最大值后累加贡献即可,注意特判最大值为$1$的情况。

    时间复杂度$O(n+m)$。

    #include<cstdio>
    const int N=2000010,P=1000000007;
    int n,m,i,f[N],r[N],ans;
    inline int cal(int x,int y){
      if(x<0)return 0;
      x>>=1;
      if(x==0)return 1;
      return 1LL*f[x+y]*r[x]%P*r[y]%P;
    }
    int main(){
      scanf("%d%d",&n,&m);
      for(f[0]=f[1]=r[0]=r[1]=1,i=2;i<=n;i++){
        f[i]=1LL*f[i-1]*i%P;
        r[i]=-1LL*r[P%i]*(P/i)%P;
        while(r[i]<0)r[i]+=P;
      }
      for(i=2;i<=n;i++)r[i]=1LL*r[i]*r[i-1]%P;
      if(n&&m)ans=1;
      for(i=2;i<=m;i++){
        (ans+=cal(n-i,i-1))%=P;
        (ans+=cal(n-i-1,i-1))%=P;
      }
      return printf("%d",ans),0;
    }
    

      

  • 相关阅读:
    Vuex的使用
    vue的props属性,vue的插槽
    ES6 Promise对象
    ES6 Map对象以及Set对象
    函数作用域以及块级作用域
    组件之间的传值-$refs&$parent
    Vue中父子组件的传值
    v-on 以及v-model的修饰符以及vue的常用指令
    时间线
    readline和xreadline的区别
  • 原文地址:https://www.cnblogs.com/clrs97/p/5149888.html
Copyright © 2011-2022 走看看