답안 #753511

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
753511 2023-06-05T12:13:11 Z Fidan K개의 묶음 (IZhO14_blocks) C++17
0 / 100
1 ms 432 KB
#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=6;
const ll inf=(1e9);
vector<vector<ll>> dp(N, vector<ll> (K, inf));
vector<vector<ll>> mx(N, vector<ll> (N));
vector<ll> a(N);
ll sol(ll n, ll k){
	if(n<k) return inf;
	if(n==0 && k==0) return 0;
	if(k==0 && n>0) return inf;
	if(k==1) return mx[1][k];
	if(dp[n][k]!=inf) return dp[n][k];
	rep(i, 0, n){
		dp[n][k]=min(dp[n][k], sol(i, k-1)+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]);
		}
	}
	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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 432 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 432 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 432 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -