[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