Submission #639617

#TimeUsernameProblemLanguageResultExecution timeMemory
639617luanaamorimK blocks (IZhO14_blocks)C++14
53 / 100
16 ms32152 KiB
#include <iostream> #include <queue> #include <string> #include <algorithm> #include <vector> #include <cmath> #include <iomanip> #include <map> #include <cstring> #include <set> #include <stack> #include <bitset> #define MAX (int) 2e3 #define ll long long #define INF (ll)1e9 using namespace std; ll n, m, arr[MAX], dp[MAX][101], maior[MAX][MAX], memo[MAX][MAX], l, r, resp; ll f(int i, int k) { if (k < 0) return INF; if (i > n) return (k?INF:0); if (~memo[i][k]) return memo[i][k]; ll resp = INF; for (int j = i; j <= n; j++) resp = min(resp, f(j+1, k-1) + maior[i][j]); return memo[i][k] = resp; } // ll dct(int i, int j, int l, int r) // { // int mid = (i+j)>>1; // //calcular dp para um k, no range [i..j] // for () // int optmid = f(1, n).second; // if (i == j) return f(1, n).first; // return min(dct(i, mid-1, l, optmid), dct(mid+1, j, optmid, r)); // } int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> arr[i]; resp = max(resp, arr[i]); } for (int i = 1; i <= n; i++) for (int j = i; j <= n; j++) maior[i][j] = max(arr[j], maior[i][j-1]); for (int i = 0; i <= n+1; i++) for (int j = 0; j <= m; j++) dp[i][j] = INF; dp[n+1][0] = 0; for (int i = n; i >= 1; i--) { for (int k = 1; k <= m; k++) { for (int j = i; j <= n; j++) dp[i][k] = min(dp[i][k], dp[j+1][k-1] + maior[i][j]); } } // for (int i = 1; i < m; i++) // dct(1, n, 1, n); memset(memo, -1, sizeof memo); cout << dp[1][m] << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...