-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path479E.cpp
More file actions
73 lines (68 loc) · 1.48 KB
/
479E.cpp
File metadata and controls
73 lines (68 loc) · 1.48 KB
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
69
70
71
72
73
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
const int mx = 1e7+2;
const int INF = 1e18;
int fact[mx];
int binpow(int a,int n)
{
if(!n) return 1;
if(n==1) return a;
if(n%2==1) return a*binpow(a,n-1);
else
{
int t = binpow(a,n/2);
return t*t;
}
}
int inverse(int x)
{
return binpow(x,mod-2);
}
int div_mod(int a, int b)
{
return a*inverse(b)%mod;
}
int cnk(int n, int k)
{
if(n<k) return 0;
return div_mod(fact[n],fact[k]*fact[n-k]%mod);
}
int gcd(int a, int b)
{
if(!b)return a;
return gcd(b,a%b);
}
int sum(int l, int r,vector<int>&a)
{
if(l > r) return 0;
if(!l) return a[r];
return (a[r]-a[l-1]+mod)%mod;
}
int main()
{
int n,a,b,k;
cin >> n >> a >> b >> k;
vector<vector<int> > dp(k+1,vector<int>(n+1,0));
vector<int> pref(n+1,0);
vector<int> new_pref(n+1,0);
for(int i = a; i <= n; i++) pref[i] = 1;
dp[0][a]=1;
for(int i = 1; i <= k; i++) {
new_pref.clear();
for(int j = 1; j <= n; j++) {
new_pref[j]=new_pref[j-1];
if(j==b) continue;
if(j < b)
dp[i][j] = (sum(1,j-1,pref)+sum(j+1,(b+j - 1)/2 ,pref))%mod;
else{
dp[i][j] = (sum(j+1,n,pref)+sum((b+j+2)/2 , j-1,pref))%mod;
}
new_pref[j]=(new_pref[j]+dp[i][j])%mod;
}
swap(pref,new_pref);
}
int ans = 0;
for(int i = 1; i <= n; i++) ans =(ans+dp[k][i])%mod;
cout << ans;
}