• 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;
    }
  • 相关阅读:
    手指抽搐强迫症 之 APM病理分析器 v0.0.0.3 (11月24日更新)
    [转帖]修改MySql密码及访问限制设置详解
    C#学习笔记
    CodeSmith快速向导
    奇葩的maxscript
    MASM中可以定义的变量类型
    js琐记
    史上最全的css hack(ie69,firefox,chrome,opera,safari)
    逆向win32程序的思路琐记
    makefile伪目标
  • 原文地址:https://www.cnblogs.com/mzyy1001/p/13688632.html
Copyright © 2020-2023  润新知