[HDOJ5773] The all-purpose Zero (greedy, DP)

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5773

Test instructions: The number of N, where 0 can be replaced by any number, ask how to replace 0 to make the entire sequence of the LIS longest.

0 can be replaced with any number, it is obvious that no matter how long the case is 0 all use. This is the line of thought, the maintenance of the prefix and sum represents 0 of the number, in all numbers minus 0 before the number, ask the LIS on the line. This is a very greedy and clever.

1#include <bits/stdc++.h>2 using namespacestd;3 4 Const intMAXN =100100;5 intN;6 intA[MAXN], S[MAXN], SUM[MAXN];7 intDP[MAXN];8 BOOLVIS[MAXN];9 Ten intBsintllintRrintv) { One      while(LL <=RR) { A         intMM = (ll + RR) >>1; -         if(s[mm] < v) LL = mm +1; -         Elserr = mm-1; the     } -     returnll; - } -  + intMain () { -     //freopen ("in", "R", stdin); +     intT, _ =1; Ascanf"%d", &T); at      while(t--) { -printf"Case #%d:", _++); -Memset (DP,0,sizeof(DP)); -memset (s),0x7f,sizeof(s)); -memset (SUM,0,sizeof(sum)); -memset (Vis,0,sizeof(Vis)); inscanf"%d", &n); -          for(inti =1; I <= N; i++) { toscanf"%d", &a[i]); +         } -          for(inti =1; I <= N; i++) { the             if(A[i] = =0) Sum[i] = sum[i-1] +1; *             ElseSum[i] = sum[i-1]; $         }Panax Notoginseng          for(inti =1; I <= N; i++) { -             if(A[i] = =0) { theVis[i] =1; +                 Continue; A             } theA[i]-=Sum[i]; +         } -         intRET =0; $          for(inti =1; I <= N; i++) { $             if(Vis[i])Continue; -Dp[i] = BS (1, I, A[i]); -S[dp[i]] =min (S[dp[i]], a[i]); theRET =Max (ret, dp[i]); -         }Wuyiprintf"%d\n", ret+sum[n]); the     } -     return 0; Wu}

[HDOJ5773] The all-purpose Zero (greedy, DP)

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.