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)