ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213982 | #2662. 折跃 | wanghanyu393 | 100 | 3184ms | 98840kb | C++11 | 970b | 2024-11-14 21:06:12 | 2024-11-14 23:07:14 |
answer
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 5e3 + 5, mod = 1e9 + 7;
int dp[N][N];
void solve(){
int n, a, b, k;
cin >> n >> a >> b >> k;
dp[0][a] = 1;
for(int i = 1; i <= k; i++){
for(int j = 1; j <= n; j++){
int dis = abs(j - b);
int l = max(1, j - dis + 1), r = min(n, j + dis - 1);
dp[i][l] = (dp[i][l] + dp[i - 1][j]) % mod;
dp[i][j] = (dp[i][j] - dp[i - 1][j] + mod) % mod;
dp[i][j + 1] = (dp[i][j + 1] + dp[i - 1][j]) % mod;
dp[i][r + 1] = (dp[i][r + 1] - dp[i - 1][j] + mod) % mod;
}
for(int j = 1; j <= n; j++) dp[i][j] = (dp[i][j - 1] + dp[i][j]) % mod;
}
int ans = 0;
for(int i = 1; i <= n; i++) ans = (ans + dp[k][i]) % mod;
cout << ans << '\n';
}
int main(){
int t = 1;
//cin >> t;
while(t--){
solve();
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1616kb
input:
98 18 22 94
output:
27076018
result:
ok single line: '27076018'
Test #2:
score: 10
Accepted
time: 1ms
memory: 1600kb
input:
95 94 73 92
output:
748455277
result:
ok single line: '748455277'
Test #3:
score: 10
Accepted
time: 352ms
memory: 98628kb
input:
4674 2740 4172 4983
output:
454585991
result:
ok single line: '454585991'
Test #4:
score: 10
Accepted
time: 422ms
memory: 98840kb
input:
4981 813 4046 4994
output:
226418975
result:
ok single line: '226418975'
Test #5:
score: 10
Accepted
time: 412ms
memory: 95240kb
input:
4595 3757 519 4810
output:
194357577
result:
ok single line: '194357577'
Test #6:
score: 10
Accepted
time: 401ms
memory: 95452kb
input:
4902 277 2317 4821
output:
641852228
result:
ok single line: '641852228'
Test #7:
score: 10
Accepted
time: 370ms
memory: 98764kb
input:
4516 1607 639 4990
output:
973001631
result:
ok single line: '973001631'
Test #8:
score: 10
Accepted
time: 460ms
memory: 92076kb
input:
4823 1127 3840 4648
output:
431104558
result:
ok single line: '431104558'
Test #9:
score: 10
Accepted
time: 443ms
memory: 95380kb
input:
4937 3261 2918 4817
output:
638296884
result:
ok single line: '638296884'
Test #10:
score: 10
Accepted
time: 323ms
memory: 95588kb
input:
4744 135 2414 4828
output:
30641258
result:
ok single line: '30641258'