# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
99924 | MohamedAhmed0 | Cave (IOI13_cave) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int dp[105][105][7] ;
int arr[105] ;
int n , k ;
int solve(int idx , int idx2 , int cnt)
{
if(cnt > k)
return 1e9 ;
if(idx == n)
{
if(cnt != k)
return 1e9 ;
return arr[idx2] ;
}
int &ret = dp[idx][idx2][cnt] ;
if(ret != -1)
return ret ;
if(idx == 0)
{
ret = solve(idx+1 , 0 , 1) ;
return ret ;
}
ret = solve(idx+1 , idx , cnt+1) + arr[idx2] ;
if(arr[idx] > arr[idx2])
idx2 = idx ;
ret = min(ret , solve(idx+1 , idx2 , cnt));
return ret ;
}
int main()
{
memset(dp , -1 , sizeof(dp));
scanf("%d %d" , &n , &k) ;
for(int i = 0 ; i < n ; ++i)
cin>>arr[i] ;
return cout<<solve(0 , 0 , 0)<<"\n" , 0 ;
}