Submission #753519

#TimeUsernameProblemLanguageResultExecution timeMemory
753519FidanK blocks (IZhO14_blocks)C++17
0 / 100
1 ms468 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, a, b) for(ll i=ll(a); i<ll(b); i++) #define repn(i, a, b) for(ll i=ll(b)-1; i>=ll(a); i--) #define ff first #define ss second #define si size() #define pb push_back #define be begin() #define en end() const ll N=110; const ll K=110; const ll inf=(1e9); vector<vector<ll>> dp(N, vector<ll> (K, -1)); vector<vector<ll>> mx(N, vector<ll> (N)); vector<ll> pre(N); vector<ll> a(N); ll sol(ll n, ll k){ if(n<k) return -1; if(k==1) return mx[1][k]; if(k==n) return pre[k]; if(dp[n][k]!=-1){ return dp[n][k]; } rep(i, 0, n){ ll x=sol(i, k-1); if(x!=-1){ if(dp[n][k]==-1) dp[n][k]=x+mx[i+1][n]; else dp[n][k]=min(dp[n][k], x+mx[i+1][n]); } } return dp[n][k]; } void solve(){ ll n, k; cin>>n>>k; rep(i, 1, n+1){ cin>>a[i]; } rep(i, 1, n+1){ mx[i][i]=a[i]; rep(j, i+1, n+1){ mx[i][j]=max(a[j], mx[i][j-1]); } } rep(i, 1, n+1){ pre[i]=pre[i-1]+a[i]; } cout<<sol(n, k); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); ll t=1; //~ cin>>t; while(t--){ solve(); } 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...