hrbust/OJ 1334 Best Mood "max increment sub-sequence && maximum value"

Source: Internet
Author: User

The best mood

time limit:1000 MS

memory limit:65536 K

 

total submit:200

Total accepted:55

RATING: 

special judge:  no

 

Description

As the saying goes, "There is a cloudy moon, people have joys and sorrows." ”。

Although everyone is not so sad, but the mood fluctuations are unavoidable.

MM mood will also have fluctuations, mood good mood value is high, mood bad mood value is low, every hour is different, GG want to know mm the longest rise mood value of sub-sequence, so GG just good ...

Give the mood value of n hours successively by time E[i],gg requires a longest subsequence, making the subsequence e1< e2<e3<e4. <ek, and makes e1+e2+e3+. +ek and the largest.

Input

There are multiple sets of data, for each set of data, the first line is an integer n (<=1000), followed by n integer ei.

Output

Each set of data outputs a row that contains two numbers representing the length of the oldest sequence and the and of the subsequence.

Sample Input

5

5 4 4) 4 9

Sample Output

2 14

Hint

The mood value E is within the range represented by a 32-bit signed number.

Source

Spring Contest 5-binary Search, greedy, DP




Ideas:

First we use DP to get the longest increment subsequence, and then we explore the DP "" Array value.

We know that DP "I" represents the longest increment of the length of a subsequence from 0-i, for such a set of examples:


5

5 4 4) 4 9

The corresponding DP values are:
1 1 1) 1 2


It's obvious that the longest increment subsequence has a length of 2, spicy. How do we find the largest and most important? We can choose such a scheme: from the back forward sweep, first sweep dp "I" = = longest increment subsequence length of a "I", and then find the maximum value, record the maximum value of the seat, and then the next time from this seat forward, find DP "I" = the longest increment subsequence length 1 of a "I", then record the maximum value Continues until the DP "I" ==1. These maximum values are then added and combined. So is that a happy ending?

There are examples of such a group:


4

1 9 2 3

The corresponding DP values are:

1 2 2 3


Obviously, we've also pulled down a situation like this. Then we also need to maintain a variable pre, which represents the maximum value of the last sweep evaluated. So that the current sweep to a "I" must be less than the pre to choose to record this a "I".


The idea is built, the last AC code:

#include <stdio.h> #include <string.h> #include <iostream>using namespace std; #define LL Long Long    Intll a[10000];int dp[10000];ll output;void dfs (int tmp,int k,int pre) {if (tmp==0) return;    int POS;    ll Maxn=0; for (int i=k;i>=0;i--) {if (Tmp==dp[i]) {if (A[I]&GT;MAXN) {if (pr e==-1| |                    A[i]<pre) {pos=i;                Maxn=a[i];    }}}} OUTPUT+=MAXN; DFS (TMP-1,POS,MAXN);}    int main () {int n;        while (~SCANF ("%d", &n)} {if (n==0) break;        Memset (Dp,0,sizeof (DP));        for (int i=0; i<n; i++) {scanf ("%lld", &a[i]);            } if (n==1) {printf ("1%lld\n", a[0]);        Continue        } dp[0]=1;        int ans=0;            for (int i=1; i<n; i++) {int maxn=0; for (int j=0; j<i; J + +) {if (a[j]<a[I]&AMP;&AMP;DP[J]&GT;MAXN) {maxn=dp[j];            }} dp[i]=maxn+1;        Ans=max (Dp[i],ans);        } output=0;        printf ("%d", ans);        DFS (ANS,N-1,-1);    printf ("%lld\n", output); }}






hrbust/OJ 1334 Best Mood "max increment sub-sequence && maximum value"

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.