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>
#define pii pair <int, int>
#define fr first
#define sc second
#define int long long
#define N 4010
using namespace std;
int range[N][N];
int v[N];
int dp[N][N];
int n, d, t;
int solve(int l, int r){
if(l > r) return 0;
if(range[l][r] != -1) return range[l][r];
if(v[l] > t) return range[l][r] = solve(l+1,r);
int sum = t - v[l] + 1;
int con = 1;
for(int i = l+1;i < l+sum;i++){
if(i > r) break;
if(v[i] <= v[l]+con){
return range[l][r] = con + solve(i, r);
}
con++;
}
return range[l][r] = con + solve(l+sum, r);
}
int32_t main(){
cin >> n >> d >> t;
memset(range, -1, sizeof range);
for(int i = 1;i <= n;i++) cin >> v[i];
for(int i = 0;i <= d;i++){
dp[0][i] = 0;
}
for(int pos = 1;pos <= n;pos++){
for(int qtd = 0;qtd <= d;qtd++){
dp[pos][qtd] = solve(1, pos);
if(qtd == 0) continue;
for(int i = pos-1;i >= 0;i--){
dp[pos][qtd] = min(dp[pos][qtd], dp[i][qtd-1] + solve(i+1, pos));
}
}
}
cout << dp[n][d] << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |