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;
    }
  • 相关阅读:
    java===单类设计模式之饿汉式与懒汉式
    java===数组工具类创建,并使用eclipse导出说明文档.html
    java===static关键字
    java===this关键字
    java=====二维数组应用
    java===算法思想锻炼
    【CSP-S 2019模拟】题解
    【CSP-S 2019模拟】题解
    【LOJ#2124】【HAOI2015】—树上染色(树形dp)
    【LOJ#2019】【AHOI / HNOI2017】—影魔(线段树+扫描线)
  • 原文地址:https://www.cnblogs.com/mzyy1001/p/13688632.html
Copyright © 2011-2022 走看看