HDU 1160 Fatmouse ' s speed recursion

Source: Internet
Author: User
Fatmouse ' s speed Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 14864 Accepted Submission (s): 6549
Special Judge


Problem Description Fatmouse believes that's fatter a mouse is, the faster it runs. To disprove this, want to take the data in a collection of mice and put as large a subset of this data as possible int o A sequence So, the weights is increasing, but the speeds is decreasing.

Input input contains data for a bunch in mice, one mouse per line, terminated by end of file.

The data for a particular mouse would consist of a pair of integers:the first representing its size in grams and the Secon D representing its speed in centimeters per second. Both integers is between 1 and 10000. The data in all test case would contain information for at most of the mice.

The same weight, the same speed, or even the same weight and speed.

Output Your program should output a sequence of lines of data; The first line should contain a number n; The remaining n lines should each contain a single positive integer (each one representing a mouse). If these n integers is m[1], m[2],..., M[n] Then it must is the case that

W[m[1]] < w[m[2] [< ... < W[m[n]]

and

S[M[1]] > s[m[2] [> ... > S[m[n]]

In order for the answer to is correct, n should be as large as possible.
All inequalities is strict:weights must is strictly increasing, and speeds must be strictly decreasing. There may is many correct outputs for a given input, and your program only needs to find one.

Sample Input
6008 1300 6000 2100 500 2000 1000 4000 1100 3000 6000 2000 8000 1400 6000 1200 2000 1900
Sample Output
4 4 5) 9 7
Source Zhejiang University Training Contest 2001
Recommend Ignatius

This recursive question ah ... The time is far more ... A little bit of a memory ... But it looks like a sort of first order ... Then find a ascending sub-sequence of what ...


#include <bits/stdc++.h> using namespace std;
    struct MO {int m,v,num;
    BOOL operator< (const MO &t) const {return m>t.m;

}
};
    int main () {mo mou[10005];
    int k,m,n,dp[10005]={0},ma,wei,cur;
    mou[0].v=0;
    mou[0].m=10005;
    dp[0]=0;
        for (k=1;cin>>m>>n;k++) {mou[k].num=k;
        Mou[k].m=m;
    Mou[k].v=n;
    } k-=1;
    Sort (mou+1,mou+k+1); for (int i=1;i<=k;i++) for (int j=0;j<i;j++) if (mou[i].v>mou[j].v&&mou[i].m<mou[j].m
    ) Dp[i]=max (dp[i],dp[j]+1);
    Cur=*max_element (dp+1,dp+k+1);
    cout<<cur<<endl;
    Wei=max_element (dp+1,dp+k+1)-DP;
    cout<<mou[wei].num<<endl;
    cur--; for (; cur>0;cur--) {for (int i=wei-1;i>=1;i--) if (dp[i]==cur&&mou[i].v<mou[wei].v&
        AMP;&AMP;MOU[I].M&GT;MOU[WEI].M) wei=i;
    cout<<mou[wei].num<<endl;
}    return 0; }

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.