UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#213950#2662. 折跃N1002686ms1288kbC++111.2kb2024-11-14 19:45:452024-11-14 23:03:56

answer

//
//  na 2662.cpp
//  Competitive Programming
//
//  Created by m2 on 2024/11/14.
//

#include <stdio.h>
#include <iostream>
using namespace std;
const int maxn = 5e3 + 5, mod = 1e9 + 7;
int n, a, b, k, las[maxn], nxt[maxn];
inline void add(int &a, int b){
    if((a += b) >= mod)
        a -= mod;
}
inline void mnu(int &a, int b){
    if((a -= b) < 0)
        a += mod;
}
inline void add(int st, int en, int &dv){
    st = max(st, 1);
    en = min(en, n);
    if(st > en)
        return;
    add(nxt[st], dv);
    mnu(nxt[en + 1], dv);
}
int main(){
    cin.tie(0)->sync_with_stdio(false);
    cin >> n >> a >> b >> k;
    nxt[a] = 1;
    while(k--){
        for(int i = 1; i <= n; ++i){
            las[i] = nxt[i];
            nxt[i] = 0;
        }
        int d;
        for(int i = 1; i <= n; ++i){
            d = abs(i - b) - 1;
            add(i - d, i - 1, las[i]);
            add(i + 1, i + d, las[i]);
        }
        for(int i = 2; i <= n; ++i){
            add(nxt[i], nxt[i - 1]);
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; ++i)
        add(ans, nxt[i]);
    cout << ans << endl;
    return 0;
}

Details

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

Test #1:

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

input:

98 18 22 94

output:

27076018

result:

ok single line: '27076018'

Test #2:

score: 10
Accepted
time: 1ms
memory: 1260kb

input:

95 94 73 92

output:

748455277

result:

ok single line: '748455277'

Test #3:

score: 10
Accepted
time: 378ms
memory: 1288kb

input:

4674 2740 4172 4983

output:

454585991

result:

ok single line: '454585991'

Test #4:

score: 10
Accepted
time: 361ms
memory: 1288kb

input:

4981 813 4046 4994

output:

226418975

result:

ok single line: '226418975'

Test #5:

score: 10
Accepted
time: 345ms
memory: 1284kb

input:

4595 3757 519 4810

output:

194357577

result:

ok single line: '194357577'

Test #6:

score: 10
Accepted
time: 337ms
memory: 1288kb

input:

4902 277 2317 4821

output:

641852228

result:

ok single line: '641852228'

Test #7:

score: 10
Accepted
time: 395ms
memory: 1284kb

input:

4516 1607 639 4990

output:

973001631

result:

ok single line: '973001631'

Test #8:

score: 10
Accepted
time: 317ms
memory: 1284kb

input:

4823 1127 3840 4648

output:

431104558

result:

ok single line: '431104558'

Test #9:

score: 10
Accepted
time: 277ms
memory: 1284kb

input:

4937 3261 2918 4817

output:

638296884

result:

ok single line: '638296884'

Test #10:

score: 10
Accepted
time: 275ms
memory: 1284kb

input:

4744 135 2414 4828

output:

30641258

result:

ok single line: '30641258'