HDU 1160 Fatmouse ' s speed--dp--(element 1 increments the oldest sequence of element 2 degradation)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.