제출 #388366

#제출 시각아이디문제언어결과실행 시간메모리
388366warner1129Stove (JOI18_stove)C++17
20 / 100
1094 ms98364 KiB
 #include <bits/stdc++.h>

using namespace std;

const int maxn = 5005;

int arr[maxn];
int dp[maxn][maxn];

void solve() {
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++) cin >> arr[i];
	m = min(m, n);
	memset(dp, 0x3f, sizeof(dp));
	dp[0][0] = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= i; j++)
			for (int k = i-1; k >= j-1; k--)
				dp[i][j] = min(dp[i][j], dp[k][j-1] + (arr[i]-arr[k+1]+1));
	cout << dp[n][m] << '\n';
}

signed main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	solve();
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...