제출 #335923

#제출 시각아이디문제언어결과실행 시간메모리
335923nafis_shifatK개의 묶음 (IZhO14_blocks)C++14
53 / 100
1097 ms1388 KiB
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;
const int mxn=1e5+5;
const int inf=1e9;
int main() {
	int n,K;
	cin>>n>>K;
	int a[n+1];
	for(int i = 1; i <= n; i++) cin>>a[i];


	int dp[n+1][K+1];


    
    for(int i = 0; i <= n; i++) {
    	for(int j = 0; j <= K; j++) {
    		dp[i][j] = inf;
    	}
    }


    dp[0][0] = 0;

    for(int i = 1; i <= n; i++) {
    	for(int j = 1; j <= min(i,K); j++) {
    		int cm = a[i];
    		for(int k = i - 1; k >= 0; k--) {
    			dp[i][j] = min(dp[i][j],dp[k][j-1] + cm);
    			cm = max(cm,a[k]);
    		}
    	}
    }
	

	cout<<dp[n][K]<<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...