• 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;
    }
  • 相关阅读:
    react 组件传值
    vue 子组件如何修改父组件data中的值??????????????????
    移动端的一些初始化 css 样式。。。
    centos7命令
    poi导出
    eclipse项目导入工作空间提示已存在问题
    maven jar包冲突问题
    layui下拉框渲染问题,以及回显问题
    两个线程交替运行——使用synchronized+wait+notify实现
    造成索引失效的情况
  • 原文地址:https://www.cnblogs.com/mzyy1001/p/13688632.html
Copyright © 2020-2023  润新知