-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC.cpp
68 lines (63 loc) · 1.43 KB
/
C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define fi first
#define se second
#define U unsigned
#define P std::pair
#define Re register
#define LL long long
#define pb push_back
#define MP std::make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(Re int i = a;i <= b;++i)
#define ROF(i,a,b) for(Re int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
#define int LL
const int ha = 1e9 + 7;
const int MAXN = 1000+5;
int n,m;
int a[MAXN];
int C[1005][1005];
inline int qpow(int a,int n){
int res = 1;
while(n){
if(n & 1) res = 1ll*res*a%ha;
a = 1ll*a*a%ha;
n >>= 1;
}
return res;
}
void prework(){
FOR(i,0,1000) C[i][0]=1;
FOR(i,1,1000)
FOR(j,1,1000)
C[i][j] = (C[i-1][j]+C[i-1][j-1])%ha;
}
signed main(){
prework();
scanf("%lld%lld",&n,&m);
FOR(i,1,m) scanf("%lld",a+i);
std::sort(a+1,a+m+1);
int now = a[1]-1,res = n-m,ans = C[res][now];res -= now;
FOR(i,2,m){
now = a[i]-a[i-1]-1;
if(!now) ans = 1ll*ans*C[res][now]%ha;
else ans = 1ll*ans*qpow(2,now-1)%ha*C[res][now]%ha;
res -= now;
}
ans = 1ll*ans*C[res][n-a[m]]%ha;
printf("%lld\n",ans);
return 0;
}