제출 #93084

#제출 시각아이디문제언어결과실행 시간메모리
93084Nodir_BobievK개의 묶음 (IZhO14_blocks)C++14
0 / 100
3 ms504 KiB
# include <iostream>

using namespace std;
	
const int N = 200;
	
int n, k;
int a[N];
long long dp[N][N];

int main()
{
	ios_base::sync_with_stdio(false);
	cin >> n >> k;
	
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= k; j++){
			dp[i][j] = 1e9 + 1;
		}
	}
	
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= min(k, i); j++){
			int mx = a[i];
			for (int k = i - 1; k >= j - 1; k--){
				dp[i][j] = min(dp[i][j], dp[k][j - 1] + mx);
				mx = max(mx, a[k]);
			}
		}
	}
	/*
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= k; j++){
			cout << dp[i][j] << ' ';
		}
		cout << endl;
	}
	*/
	
	cout << dp[n][k];
	
}
/*

5 1
1 2 3 4 5


5 5
1 2 3 4 5


*/ 

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...