zoukankan      html  css  js  c++  java
  • B-shaass and lights codeForces

    There are n lights aligned in a row. These lights are numbered 1 to n from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be swithced off at that moment) if thers's at least one adjacent light which is alread swiched on.

    He konws the initial state of lights and he's wondering how many different ways there exist to swich all the lights on.Please find ther required number of ways modulo 1000000007(109+7).

    /*************************************************************************
      > File Name: cf249c.cpp
      > Author: Henry Chen
      > Mail: 390989083@qq.com 
      > Created Time: 三  9/16 23:07:58 2020
     ************************************************************************/
    
    #include<bits/stdc++.h>
    
    using namespace std;
    const int mod = 1e9 + 7;
    const int maxn = 1e3 + 10;
    
    long long n,m;
    long long  a[maxn];
    long long fac[maxn], C[maxn][maxn];
    long long sum;
    
    int main()
    {
     fac[0] = 1ll;
     fac[1] = 1ll;
     for(int i = 2; i <= 1000; i++)
     {
      fac[i] = (fac[i-1]*2)%mod;
     }
     C[0][0] = 1;
     for(int i = 1; i <= 1000; i++)
     {
      C[i][0] = 1;
      for(int j = 1; j <= i; j++)
      {
       C[i][j] = (C[i-1][j] + C[i-1][j-1])%mod;
      }
     }
     cin >> n >> m;
     for(int i = 1; i <= m; i++)
     {
      scanf("%lld", &a[i]);
     }
     sort(a+1, a+m+1);
     sum = 1;
     long long tot  = n - m;
     for(int i = 1; i <= m; i++)
     {
      sum = (sum * C[tot][a[i]-a[i-1]-1])%mod;
      tot -= a[i] - a[i-1] - 1;
     }
     for(int i = 2; i <= m; i++)
     {
      sum = (sum * fac[a[i]-a[i-1]-1])%mod;
     }
     printf("%lld
    ",sum);
     return 0;
    }
  • 相关阅读:
    U3D不同平台载入XML文件的方法——IOS MAC Android
    C++使用规范小记
    设置角色对象可见性
    编辑器菜单操作
    U3D资源动态加载异步方案探究
    Animation动画
    Unity3D失去焦点时继续渲染
    C#打开当前目录
    组件模式代码实践(C#版本)
    Unity3D批处理脚本
  • 原文地址:https://www.cnblogs.com/mzyy1001/p/13688632.html
Copyright © 2011-2022 走看看