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; }