[Dynamic Planning] [memory-based search] computing of codevs 1011 in 2001 noip National League popularity Group

Source: Internet
Author: User

If the answer is F (N), we can obviously solve it recursively:

F (n) = F (1) + F (2) + ...... + F (n/2 ).

But n = 1000, it will obviously time out.

There may be at most N states, which have undergone a large number of repeated computations, so they can be remembered to reduce unnecessary computations.

1 # include <cstdio> 2 using namespace STD; 3 int N; 4 long memory [1001]; 5 long F (INT cur) 6 {7 if (memory [cur]) return memory [cur]; 8 long res = 1; 9 for (INT I = 1; I <= (cur> 1); I ++) RES + = f (I); 10 return memory [cur] = res; 11} 12 INT main () 13 {14 scanf ("% d", & N); 15 memory [1] = 1; 16 printf ("% LLD \ n", F (n )); 17 return 0; 18}

 

[Dynamic Planning] [memory-based search] computing of codevs 1011 in 2001 noip National League popularity Group

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.