[Dynamic Planning] [memory-based search] [Search] codevs 1262 don't pass the ball to my 2012 CCC Canadian high school student informatics ausai

Source: Internet
Author: User

It can be solved by brute-force recursion. It should not be TLE, but we should consider memory optimization.

If f (I, j) is set, it indicates the number of solutions when I is set to J.

F (I, j) = f (1, J-1) + F (2, J-1) + ...... + F (I-1, J-1) (4> = j> = 1), recursively solving from F (n, 4.

However, since there are only N * 4 statuses at most, you can simply remember them.

Initialization: f (I, 1) = 1 (1 <= I <= n-3)

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

 

[Dynamic Planning] [memory-based search] [Search] codevs 1262 don't pass the ball to my 2012 CCC Canadian high school student informatics ausai

Related Article

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.