QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#153728#6868. Klee likes making friendsneko_nyaaML 0ms0kbC++23922b2023-08-30 19:53:242023-08-30 19:53:25

Judging History

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

  • [2023-08-30 19:53:25]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:0kb
  • [2023-08-30 19:53:24]
  • 提交

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;
}

Details

Tip: Click on the bar to expand more detailed information

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

output:


result: