UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#213980#2662. 折跃STASISZHY1005345ms98760kbC++112.2kb2024-11-14 21:00:412024-11-14 23:06:57

answer

// Problem: C. 折跃
// Contest: undefined - NOIP2024训练赛 05
// URL: http://119.28.3.174/contest/1157/problem/2662
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
//#define int long long
#define fi first
#define se second
#define PII pair<int, int>

using namespace std;

const int N = 5e3 + 10, M = 1e6 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f;

int n, m, q, st, d, k, ans;
int s[N], dp[N][N], sum[N];

int dfs(int now, int k)
{
	if(!k) return 1;
	if(dp[now][k]) return dp[now][k];
	int dis = (d - now) < 0 ? now - d : d - now;
	int l = max(1, now - dis + 1), r = min(n, now + dis - 1), res = 0;
	// cout << "now = " << now << " l = " << l << " r = " << r << '\n';
	for(int i = l; i <= r; i ++) if(i != now) res = (res + dfs(i, k - 1)) % mod;
	return dp[now][k] = res;
}

struct Tree
{
	int l, r, sum;
}tr[N << 2];

inline void pushup(int x) {tr[x].sum = (tr[2 * x].sum + tr[2 * x + 1].sum) % mod;}

void build(int x, int l, int r, int id)
{
	tr[x].l = l, tr[x].r = r;
	if(l == r) 
	{
		tr[x].sum = dp[l][id];
		return;
	}
	int mid = l + r >> 1;
	build(2 * x, l, mid, id);
	build(2 * x + 1, mid + 1, r, id);
	pushup(x);
}

int query(int x, int l, int r)
{
	if(tr[x].l >= l && tr[x].r <= r) return tr[x].sum;
	int mid = tr[x].l + tr[x].r >> 1, res = 0;
	if(l <= mid) res = (res + query(2 * x, l, r)) % mod;
	if(r > mid) res = (res + query(2 * x + 1, l, r)) % mod;
	return res;
}

signed main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> st >> d >> k;
	// cout << dfs(st, k) << '\n';
	for(int i = 1; i <= n; i ++) if(i != d) dp[i][0] = 1;
	for(int p = 1; p <= k; p ++)
	{
		// build(1, 1, n, p - 1);
		for(int i = 1; i <= n; i ++) sum[i] = (sum[i - 1] + dp[i][p - 1]) % mod;
		for(int i = 1; i <= n; i ++)
		{
			// if(i == d) continue;
			int dis = abs(i - d) - 1, l = max(1, i - dis), r = min(n, i + dis);
			// dp[i][p] = (query(1, l, r) - dp[i][p - 1] + mod) % mod;
			dp[i][p] = (((sum[r] - sum[l - 1] + mod) % mod) - dp[i][p - 1] + mod) % mod;
		}
	}
	// for(int i = 1; i <= k; i ++) cout << dp[d][i] << ' ';
	// cout << '\n';
	cout << dp[st][k] << '\n';
	return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1680kb

input:

98 18 22 94

output:

27076018

result:

ok single line: '27076018'

Test #2:

score: 10
Accepted
time: 0ms
memory: 1668kb

input:

95 94 73 92

output:

748455277

result:

ok single line: '748455277'

Test #3:

score: 10
Accepted
time: 771ms
memory: 92756kb

input:

4674 2740 4172 4983

output:

454585991

result:

ok single line: '454585991'

Test #4:

score: 10
Accepted
time: 613ms
memory: 98760kb

input:

4981 813 4046 4994

output:

226418975

result:

ok single line: '226418975'

Test #5:

score: 10
Accepted
time: 539ms
memory: 91208kb

input:

4595 3757 519 4810

output:

194357577

result:

ok single line: '194357577'

Test #6:

score: 10
Accepted
time: 591ms
memory: 97216kb

input:

4902 277 2317 4821

output:

641852228

result:

ok single line: '641852228'

Test #7:

score: 10
Accepted
time: 780ms
memory: 89660kb

input:

4516 1607 639 4990

output:

973001631

result:

ok single line: '973001631'

Test #8:

score: 10
Accepted
time: 616ms
memory: 95672kb

input:

4823 1127 3840 4648

output:

431104558

result:

ok single line: '431104558'

Test #9:

score: 10
Accepted
time: 595ms
memory: 97900kb

input:

4937 3261 2918 4817

output:

638296884

result:

ok single line: '638296884'

Test #10:

score: 10
Accepted
time: 840ms
memory: 94120kb

input:

4744 135 2414 4828

output:

30641258

result:

ok single line: '30641258'