hdu1257 dp (longest ascending subsequence)

Source: Internet
Author: User

Test instructions: There is an interception system that can combat missiles, but the height of the attack will gradually decline, so in order to defend against missile attacks, it is necessary to use multiple systems, now give a list of missiles in sequence to the height of the minimum number of systems required.

This question is the longest ascending sub-sequence problem, but I actually did not think at first, the first thing I thought is to eliminate the longest descending sub-sequence, each elimination of a round is the need for an interception system, and then until all the numbers are removed can be known to a few interception system. And this is the longest descent sub-sequence in line with DP thinking can also be justified, so that why I grow so slow, in fact, I brush DP topic on how to use DP on how to think instead of how to do out on the thought, many times this actually my progress is too small.

Well, this is WA, I am not very clear why WA, but I was so knocked at the time I think this idea is very messy, so a is actually not very good for me.

WA knew to find a new way, so I think of another approach, the side of the digital side of the building system, for a number, if the previous system has a minimum value greater than this number, then the system can intercept the missile, then the minimum value of the interception system is changed to this number, And if this number is greater than the minimum of all previous interception systems, then it means that no system can intercept the missile, and I will re-establish a system whose minimum value is the current number. In fact, I do not know whether it is right, because there is a point to consider, when there are many systems can intercept it, I should optimize which one, I chose the smallest, obviously I do not know this is not right. And then I got a ' ' ' unwilling a '

After asking seniors, my seniors told me that it was just one of the longest ascending subsequence. To think about, for this longest ascending subsequence, each number represents the minimum of an interception system, and since the sequence is ascending, each number can no longer intercept the next number in the sequence because the next number is larger, so the length of this subsequence is the number of interception systems. I think I'm more receptive to that, and maybe that's just because the data is weak, so it's over.

So, I feel like I'm as weak as the data.

Stupid, just stupid!

1#include <stdio.h>2#include <string.h>3#include <algorithm>4 using namespacestd;5 intdp[30001],a[30001];6 intMain () {7     intN;8      while(SCANF ("%d", &n)! =EOF) {9         intI,j,c=0;TenMemset (DP,0,sizeof(DP)); One          for(i=1; i<=n;i++){ Ascanf"%d",&a[i]); -             intf=0; -              for(j=1; j<=c;j++){ the                 if(a[i]<Dp[j]) { -f=1; -dp[j]=A[i]; -                      Break; +                 } -             } +             if(!f) dp[++c]=A[i]; ASort (dp+1, dp+c+1); at         } -printf"%d\n", c); -     } -     return 0; -}
View Code

hdu1257 dp (longest ascending subsequence)

Related Article

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.