QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#153728 | #6868. Klee likes making friends | neko_nyaa | ML | 0ms | 0kb | C++23 | 922b | 2023-08-30 19:53:24 | 2023-08-30 19:53:25 |
answer
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int a[20002], dp[20002][2002];
void solve() {
int n, m; cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
dp[0][i] = 0;
}
int ans = INF;
for (int i = 1; i <= n+1; i++) {
for (int j = 1; j < m; j++) {
dp[i][j] = INF;
}
for (int j = 1; j < m; j++) {
if (j > i) break;
dp[i][j] = min(dp[i][j], dp[i-j][m-j] + a[i]);
}
for (int j = 2; j < m; j++) {
dp[i][j] = min(dp[i][j], dp[i][j-1]);
}
/*for (int j = 1; j < m; j++) {
cout << dp[i][j] << ' ';
}
cout << '\n';*/
if (i == n+1) {
for (int j = 1; j < m; j++) {
ans = min(ans, dp[i][j]);
}
}
}
cout << ans << '\n';
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
int ts; cin >> ts;
while (ts--) {
solve();
}
return 0;
}
详细
Test #1:
score: 0
Memory Limit Exceeded
input:
11 10 9 3 6 5 7 8 8 5 6 4 7 15 4 3034 6855 8797 12515 5315 13315 3021 5948 1618 5781 1305 4266 7634 8049 5990 15 2 6722 6887 1628 19483 16034 5800 2683 3444 10818 11900 13443 5020 11435 1033 4029 15 9 8450 8445 6959 2822 15741 16970 10576 13954 16766 12222 14601 10913 1683 16651 7250 381 30 17958 71...