Submission #969237

#TimeUsernameProblemLanguageResultExecution timeMemory
969237biankK blocks (IZhO14_blocks)C++14
53 / 100
1008 ms1368 KiB
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int N, K; cin >> N >> K; vector<int> a(N); for (int i = 0; i < N; i++) { cin >> a[i]; } vector<vector<int>> dp(K + 1, vector<int>(N + 1, INF)); dp[0][0] = 0; for (int i = 1; i <= K; i++) { for (int j = i; j <= N; j++) { int maxi = 0; for (int k = j; k >= i; k--) { maxi = max(maxi, a[k - 1]); dp[i][j] = min(dp[i][j], dp[i - 1][k - 1] + maxi); } } } cout << dp[K][N] << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...