ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213947 | #2662. 折跃 | ThySecret | 100 | 1340ms | 392140kb | C++11 | 2.6kb | 2024-11-14 19:35:29 | 2024-11-14 23:03:41 |
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
// #define x first
// #define y second
#define File(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)
inline void debug() { cerr << '\n'; }
template<typename Type, typename... Other>
inline void debug(const Type& x, const Other&... y) { cerr << x << ' '; debug(y...); }
#define DEBUG(a...) cerr << "[" << #a << "] = ", debug(a);
typedef long long LL;
typedef pair<int, int> PII;
const int N = 5010;
const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
template<typename Type>
inline void read(Type &res)
{
res = 0;
int ch = getchar(), flag = 0;
while (!isdigit(ch)) flag |= ch == '-', ch = getchar();
while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
res = flag ? -res : res;
}
template<typename Type, typename... Other>
inline void read(Type &res, Other&... y) { read(res), read(y...); }
int n, st, ed, k;
int f[N][N], sum[N][N];
namespace BF
{
void solve()
{
f[0][st] = 1;
for (int i = 0; i < k; i ++)
{
for (int j = 1; j <= n; j ++)
{
if (j == ed) continue;
if (j < ed)
{
for (int t = max(1LL, j - (ed - j) + 1); t < ed; t ++)
if (t != j) f[i + 1][t] = (f[i + 1][t] + f[i][j]) % mod;
}
else
{
for (int t = ed + 1; t <= min(n, j + j - ed - 1); t ++)
if (t != j) f[i + 1][t] = (f[i + 1][t] + f[i][j]) % mod;
}
}
}
int ans = 0;
for (int i = 1; i <= n; i ++) ans = (ans + f[k][i]) % mod;
cout << ans << '\n';
}
}
signed main()
{
read(n, st, ed, k);
// if (n <= 500) BF::solve();
f[0][st] = 1;
for (int i = st; i <= n; i ++) sum[0][i] = 1;
for (int i = 1; i <= k; i ++)
{
for (int j = 1; j <= n; j ++)
{
// if (j == ed) continue;
if (j < ed)
{
int cur = j + ed - 1 >> 1;
f[i][j] = (sum[i - 1][cur] - f[i - 1][j] + mod) % mod;
}
else if (j > ed)
{
int cur = j + ed + 2 >> 1;
f[i][j] = (sum[i - 1][n] - sum[i - 1][cur - 1] - f[i - 1][j] + 2 * mod) % mod;
}
sum[i][j] = (sum[i][j - 1] + f[i][j]) % mod;
// DEBUG(i, j, f[i][j], sum[i][j]);
}
}
cout << sum[k][n] << '\n';
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 2056kb
input:
98 18 22 94
output:
27076018
result:
ok single line: '27076018'
Test #2:
score: 10
Accepted
time: 0ms
memory: 2028kb
input:
95 94 73 92
output:
748455277
result:
ok single line: '748455277'
Test #3:
score: 10
Accepted
time: 152ms
memory: 391260kb
input:
4674 2740 4172 4983
output:
454585991
result:
ok single line: '454585991'
Test #4:
score: 10
Accepted
time: 188ms
memory: 392140kb
input:
4981 813 4046 4994
output:
226418975
result:
ok single line: '226418975'
Test #5:
score: 10
Accepted
time: 132ms
memory: 377708kb
input:
4595 3757 519 4810
output:
194357577
result:
ok single line: '194357577'
Test #6:
score: 10
Accepted
time: 184ms
memory: 378600kb
input:
4902 277 2317 4821
output:
641852228
result:
ok single line: '641852228'
Test #7:
score: 10
Accepted
time: 162ms
memory: 391812kb
input:
4516 1607 639 4990
output:
973001631
result:
ok single line: '973001631'
Test #8:
score: 10
Accepted
time: 154ms
memory: 365052kb
input:
4823 1127 3840 4648
output:
431104558
result:
ok single line: '431104558'
Test #9:
score: 10
Accepted
time: 178ms
memory: 378268kb
input:
4937 3261 2918 4817
output:
638296884
result:
ok single line: '638296884'
Test #10:
score: 10
Accepted
time: 190ms
memory: 379144kb
input:
4744 135 2414 4828
output:
30641258
result:
ok single line: '30641258'