UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213942#2662. 折跃erican1001531ms183468kbC++112.0kb2024-11-14 19:29:322024-11-14 23:03:23

answer

// Problem: C. 折跃
// Contest: undefined - NOIP2024训练赛 05
// URL: http://noi.ac/contest/1157/problem/2662
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
// Challenger: Erica N
// ----
// 
#include<bits/stdc++.h>

using namespace std;
#define rd read()
#define ull unsigned long long
#define int long long 
#define pb push_back
#define itn int
#define ps second 
#define pf first


#define rd read()
int read(){
  int xx = 0, ff = 1;char ch = getchar();
  while (ch < '0' || ch > '9'){
    if (ch == '-')ff = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')xx = xx * 10 + (ch - '0'), ch = getchar();
  return xx * ff;
}
#define zerol = 1
#ifdef zerol
#define cdbg(x...) do { cerr << #x << " -> "; err(x); } while (0)
void err() {cerr << endl;}
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) {
	for (auto v: a) cerr << v << ' ';err(x...);
}
template<typename T, typename... A>
void err(T a, A... x) {
	cerr << a << ' ';err(x...);
}
#else
#define dbg(...)
#endif
const int N=5e3+5;
const ull P=137;
const int INF=1e18+7;
const int MOD=1e9+7;
/*

策略


*/	


int f[N][N];//第i次后在j的方案数
int n,a,b,K,pre[N];

void solve(){
	for(int i=1;i<b;i++)pre[i]=pre[i-1]+f[0][i];
	
	for(int i=1;i<=K;i++){
		for(int j=1;j<b;j++){
			f[i][j]=((pre[min(b-1,j+(b-j-1)/2)]-f[i-1][j])%MOD+MOD)%MOD;
		}
		
		for(int j=1;j<b;j++)pre[j]=(pre[j-1]+f[i][j])%MOD;
	}
	
	
	int ans=0;
	for(int i=1;i<b;i++){
		ans=(ans+f[K][i])%MOD;
	}
	
	cout<<ans<<endl;
	
}


void solvee(){
	for(int j=n;j>b;j--)pre[j]=(pre[j+1]+f[0][j])%MOD;
	
	for(int i=1;i<=K;i++){
		for(int j=b+1;j<=n;j++){
			f[i][j]=((pre[max(b+1,j-(j-b-1)/2)]-f[i-1][j])%MOD+MOD)%MOD;
		}
		
		for(int j=n;j>b;j--)pre[j]=(pre[j+1]+f[i][j])%MOD;
	}
	
	
	int ans=0;
	for(int i=b+1;i<=n;i++){
		ans=(ans+f[K][i])%MOD;
	}
	
	cout<<ans<<endl;
	
}

signed main(){
	 n=rd;
	 a=rd,b=rd,K=rd;
	
	
	
	f[0][a]=1;
	
	if(a<b)solve();
	else solvee();
	
}

详细

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

Test #1:

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

input:

98 18 22 94

output:

27076018

result:

ok single line: '27076018'

Test #2:

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

input:

95 94 73 92

output:

748455277

result:

ok single line: '748455277'

Test #3:

score: 10
Accepted
time: 233ms
memory: 183468kb

input:

4674 2740 4172 4983

output:

454585991

result:

ok single line: '454585991'

Test #4:

score: 10
Accepted
time: 221ms
memory: 178960kb

input:

4981 813 4046 4994

output:

226418975

result:

ok single line: '226418975'

Test #5:

score: 10
Accepted
time: 241ms
memory: 173572kb

input:

4595 3757 519 4810

output:

194357577

result:

ok single line: '194357577'

Test #6:

score: 10
Accepted
time: 130ms
memory: 107660kb

input:

4902 277 2317 4821

output:

641852228

result:

ok single line: '641852228'

Test #7:

score: 10
Accepted
time: 180ms
memory: 172264kb

input:

4516 1607 639 4990

output:

973001631

result:

ok single line: '973001631'

Test #8:

score: 10
Accepted
time: 207ms
memory: 159156kb

input:

4823 1127 3840 4648

output:

431104558

result:

ok single line: '431104558'

Test #9:

score: 10
Accepted
time: 138ms
memory: 96404kb

input:

4937 3261 2918 4817

output:

638296884

result:

ok single line: '638296884'

Test #10:

score: 10
Accepted
time: 181ms
memory: 111472kb

input:

4744 135 2414 4828

output:

30641258

result:

ok single line: '30641258'