#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
const int N=5005;
int dp[N][N];
int a[N];
signed main(){
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
dp[i][j]=1e9;
}
}
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++)cin>>a[i];
dp[0][0]=0;
int ans=n;
for(int i=1;i<=n;i++){
for(int j=0;j<i;j++){
for(int hi=0;hi<=1000;hi++){
for(int hj=0;hj<=1000;hj++){
if(hi-hj>k)continue;
if(hi!=a[i]){
dp[i][hi]=min(dp[i][hi],dp[j][hj]+1);
ans=min(ans,dp[i][hi]);
}
}
}
}
}
cout<<ans;
}
# | 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... |