HDU 4960 Another OCD patient (memory-based search)

Source: Internet
Author: User

HDU 4960 Another OCD patient

Question Link

Memory-based search, because each shard value is a positive number, so each prefix and suffix are incremented, you can use twopointer to find each equal position, and then the next interval is equivalent to a subproblem, it can be searched with memory, and the complexity is close to O (N ^ 2)

Code:

 # include 
   
     # include 
    
      # include 
     
       using namespace STD; const int INF = 0x3f3f3f3f; const int n= 5005; typedef long ll; int n, a [n], DP [N] [N]; ll V [N], pre [N]; void Init () {for (INT I = 1; I <= N; I ++) {scanf ("% i64d", & V [I]); pre [I] = pre [I-1] + V [I];} For (INT I = 1; I <= N; I ++) scanf ("% d", & A [I]); memset (DP,-1, sizeof (DP);} int solve (INT L, int R) {If (DP [l] [r]! =-1) return DP [l] [r]; DP [l] [r] = A [R-l + 1]; If (L> = r) return DP [l] [r] = 0; int now = L; for (INT I = r; I> = L; I --) {While (pre [now]-pre [L-1] 
      

     
    
   


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.