It is obvious that this is a DP, and then it begins to define the state ...
F[I][J] said that I had finished processing I corn, the highest value of J times, the remaining corn maximum.
F[I][J] = max{f[x][y]+1} (x<i,y<=j,h[x]+y<=h[i]+j).
So we can use two-dimensional tree-like array to maintain the maximum value, the first dimension maintenance of the number of times, the second dimension to maintain the height of the high.
1#include <iostream>2#include <cstdlib>3#include <cstdio>4#include <cstring>5 6 using namespacestd;7 8 Const intN =10000+5;9 Ten intN, M, ans, h[n], f[n]; One A structtree{ - inta[5510][510]; -Tree () {memset (A,0,sizeofa);} the - intLowbit (intx) {returnx& (-x);} - - voidUpdateintXintYintd) { + for(intx = x; X <=5500; X + =lowbit (x)) - for(inty = y; Y <= m+1; Y + =lowbit (y)) +A[x][y] =Max (a[x][y],d); A } at intQueryintXintY) { - intRET =0; - for(intx = x; X X-=lowbit (x)) - for(inty = y; Y Y-=lowbit (y)) -RET =Max (ret,a[x][y]); - returnret; in } - }t; to intMain () { +scanf"%d%d", &n, &m); - for(inti =1; I <= N; i + + ){ the intX scanf"%d", &x); * for(intj = m; J >=0; J-- ){ $F[J] = T.query (x+j,j+1)+1;Panax NotoginsengAns =Max (ans,f[j]); -T.update (x+j,j+1, F[j]); the } + } Aprintf"%d\n", ans); the return 0; +}
View Code
"BZOJ3594" "SCOI2014" the corn field of Uncle Fang