ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#213963 | #2662. 折跃 | Running_a_way | 100 | 3206ms | 196700kb | C++ | 1017b | 2024-11-14 20:10:44 | 2024-11-14 23:05:29 |
answer
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
const int N = 5010, mod = 1e9 + 7;
ll f[N][N], n, a, b, K, s[N];
#define myabs(x) ((x) > 0 ? (x) : -(x))
ll get(ll l, ll r) {
if(l > r) return 0;
return ((s[r] - s[l - 1]) % mod + mod) % mod;
}
int main() {
scanf("%lld%lld%lld%lld", &n, &a, &b, &K);
f[0][a] = 1;
for (int i = 1; i <= n; i++) s[i] = (s[i - 1] + f[0][i]) % mod;
for (int k = 1; k <= K; k++) {
for (int i = 1; i <= n; i++) {
if(i == b) continue;
int l, r;
if(i < b) l = 1, r = (i + b + 1) / 2 - 1;
else l = (i + b) / 2 + 1, r = n;
f[k][i] = (get(l, i - 1) + get(i + 1, r)) % mod;
}
for (int i = 1; i <= n; i++) s[i] = (s[i - 1] + f[k][i]) % mod;
}
// for (int i = 1; i <= K; i++) {
// for (int j = 1; j <= n; j++) cout << f[i][j] << ' ';
// cout << '\n';
// }
printf("%lld\n", s[n]);
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1640kb
input:
98 18 22 94
output:
27076018
result:
ok single line: '27076018'
Test #2:
score: 10
Accepted
time: 0ms
memory: 1624kb
input:
95 94 73 92
output:
748455277
result:
ok single line: '748455277'
Test #3:
score: 10
Accepted
time: 450ms
memory: 196268kb
input:
4674 2740 4172 4983
output:
454585991
result:
ok single line: '454585991'
Test #4:
score: 10
Accepted
time: 378ms
memory: 196700kb
input:
4981 813 4046 4994
output:
226418975
result:
ok single line: '226418975'
Test #5:
score: 10
Accepted
time: 342ms
memory: 189500kb
input:
4595 3757 519 4810
output:
194357577
result:
ok single line: '194357577'
Test #6:
score: 10
Accepted
time: 372ms
memory: 189928kb
input:
4902 277 2317 4821
output:
641852228
result:
ok single line: '641852228'
Test #7:
score: 10
Accepted
time: 366ms
memory: 196540kb
input:
4516 1607 639 4990
output:
973001631
result:
ok single line: '973001631'
Test #8:
score: 10
Accepted
time: 443ms
memory: 183156kb
input:
4823 1127 3840 4648
output:
431104558
result:
ok single line: '431104558'
Test #9:
score: 10
Accepted
time: 484ms
memory: 189772kb
input:
4937 3261 2918 4817
output:
638296884
result:
ok single line: '638296884'
Test #10:
score: 10
Accepted
time: 371ms
memory: 190200kb
input:
4744 135 2414 4828
output:
30641258
result:
ok single line: '30641258'