"BZOJ3594" "SCOI2014" the corn field of Uncle Fang

Source: Internet
Author: User

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

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.