Submission #1129748

#TimeUsernameProblemLanguageResultExecution timeMemory
1129748zhasynK blocks (IZhO14_blocks)C++20
53 / 100
1 ms840 KiB
#include <bits/stdc++.h> #define pb push_back #define pf push_front using namespace std; #define F first #define S second typedef long long ll; #define pii pair <int, int> #define pll pair <ll, ll> typedef long double ld; const ll N = 3000 + 100, M = 500 + 10, len = 315, inf = 1e18; const ll mod = 998244353; ll um(ll a, ll b){ return (1LL * a * b) % mod; } ll subr(ll a, ll b){ return ((1LL * a - b) % mod + mod) % mod; } ll bp(ll x, ll step){ ll res = 1; while(step){ if(step & 1) res = um(res, x); x = um(x, x); step /= 2; } return res; } ll inv(ll x){ return bp(x, mod - 2); } ll a[N], dp[N][N]; int main() { //ios_base::sync_with_stdio(false); //cin.tie(nullptr); //cout.tie(nullptr); int n, k; cin >> n >> k; for(int i = 1; i <= n; i++){ cin >> a[i]; } for(int i = 0; i <= 100; i++){ for(int j = 0; j <= 100; j++){ dp[i][j] = -1; } } dp[0][0] = 0; for(int i = 1; i <= n; i++){ ll mx = 0; for(int j = i; j <= n; j++){ mx = max(mx, a[j]); for(int l = 1; l <= k; l++){ if(dp[i - 1][l - 1] == -1) continue; if(dp[j][l] == -1) dp[j][l] = dp[i - 1][l - 1] + mx; else dp[j][l] = min(dp[j][l], dp[i - 1][l - 1] + mx); } } } cout << dp[n][k]; 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...