QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#153729#6868. Klee likes making friendsneko_nyaaAC ✓151ms19364kbC++23984b2023-08-30 19:54:582023-08-30 19:54:59

Judging History

你现在查看的是最新测评结果

  • [2023-08-30 19:54:59]
  • 评测
  • 测评结果:AC
  • 用时:151ms
  • 内存:19364kb
  • [2023-08-30 19:54:58]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int INF = 1000000000;
const int MX = 2002;
int a[MX*10], dp[MX][MX];

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 % MX][j] = INF;
		}

		for (int j = 1; j < m; j++) {
			if (j > i) break;
			dp[i % MX][j] = min(dp[i % MX][j], dp[(i-j+MX) % MX][m-j] + a[i]);
		}

		for (int j = 2; j < m; j++) {
			dp[i % MX][j] = min(dp[i % MX][j], dp[i % MX][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 % MX][j]);
			}
		}
	}
	cout << ans << '\n';
}

signed main() {
	ios::sync_with_stdio(0); cin.tie(0);
	
	int ts; cin >> ts;
	while (ts--) {
		solve();
	} 

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 151ms
memory: 19364kb

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...

output:

9
33346
120359
15081
55485
157758
106256
880
1898
657
739

result:

ok 11 lines