水太......
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <vector> using namespace std; typedef long long int LL; const int maxn=100100; int n,K; LL h[maxn],sum[maxn],tr[maxn]; vector<LL> road; int main() { cin>>n>>K; sum[1]=1; int maxl=1; for(int i=1;i<=n;i++) { cin>>h[i]; sum[i]=1; for(int j=max(1,i-500);j<i;j++) { if(abs(h[j]-h[i])>=K&&sum[j]+1>sum[i]) { sum[i]=sum[j]+1; tr[i]=j; } if(sum[i]>sum[maxl]) { maxl=i; } } } cout<<sum[maxl]<<endl; int T=tr[maxl]; road.push_back(maxl); while(T) { road.push_back(T); T=tr[T]; } while(road.size()) { cout<<road.back()<<" "; road.pop_back(); } return 0; }
版权声明:来自: 代码代码猿猿AC路 http://blog.csdn.net/ck_boss