[Project Euler]: Question 015

Source: Internet
Author: User

[Project Euler]: Question 015

Zhou yinhui

 

Problem description

Starting in the top left corner of a 22 grid, there are 6 routes (without backtracking) to the bottom right corner.

How many routes are there through a 2020 grid? 

 

Problem Analysis

# Include <stdio. h> # Define SZ 21 // 20*20, index from 0 to 20, so size is 21 # Define end (SZ-1) Long long grid [SZ] [SZ]; Long long test (int I, Int J) { Int record = grid [I] [J]; If (record! = 0) { Return record; } If (I = end & J = end) { Return 1; } Long long left = 0, Right = 0, total = 0; Int ni = I + 1, nj = J + 1; // Ni: Next I If (Ni <sz) { Left = test (Ni, J ); Grid [Ni] [J] = left; } If (NJ <sz) { Right = test (I, NJ ); Grid [I] [NJ] = right; } Total = left + right; Grid [I] [J] = total; Return total; } Int main () { Printf ("path count: % LLD \ n", test (0, 0 )); Return 0; }

Fast:

Real 0m0. 004 s

User 0m0. 001 S

Sys 0m0. 003 s 

 

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.