Test instructions: Find the longest sequence of weight increment speed degradation
Analysis: The same as the longest increment subsequence, but the first thing to do is to sort the weight in ascending order and then find the longest degradation subsequence.
Code:
#include <iostream> #include <algorithm> #include <cstdio>using namespace std;struct node{int w,s;int t;} A[2000];int n,i;struct h{int x;int pre;} Dp[2000];int Ans[2000],g;bool CMP (node P,node q) {if (P.W!=Q.W) return P.w<q.w;return P.s>q.s;} int max (int p,int q) {return p>q?p:q;} void prin (int index) {int j=index; if (dp[j].pre!=j) { prin (dp[j].pre); cout<<a[j].t<<endl; } else cout<<a[j].t<<endl; return;} int main () {I=0,g=0;int mx=-1,index; while (CIN>>A[I].W>>A[I].S) i++;for (int j=0;j<i;j++) {a[j].t=j+1;} Sort (a,a+i,cmp); for (int j=0;j<i;j++) { dp[j].x=1; Dp[j].pre=j;} for (int j=0;j<i;j++) {for (int k=0;k<j;k++) {if (A[K].S>A[J].S&&A[K].W!=A[J].W) {if (Dp[j].x<dp[k] . x+1) {dp[j].x=dp[k].x+1;dp[j].pre=k;}} if (mx<dp[j].x) {mx=dp[j].x;index=j;}} } Cout<<mx<<endl;prin (index);}
HDU 1160 Fatmouse ' s speed--dp--(element 1 increments the oldest sequence of element 2 degradation)