Zzuli_summerpractice (6) POJ 270...__ Summer Camp Training

Source: Internet
Author: User
Tags time limit
G-pascal ' s travels p
Time Limit: 1000MS Memory Limit: 65536K 64bit IO Format: %i64d &%i64u

[Submit]   [Go back] [Status]

Description an n x N game board are populated with integers, one nonnegative integer per square. The goal is to travel along any legitimate path from the upper left corner to the lower right corner of the. The integer in any one of the square dictates how large a is away from that location must. If the step size would advance travel off the game board, then a step in this particular direction is forbidden. All steps must is either to the right or toward the bottom. Note that the a 0 is a dead end which prevents any further progress.


Consider the 4 x 4 board shown in Figure 1 where the solid circle the start identifies and the position IDE Ntifies the target. Figure 2 shows the three paths from the "start to" target, with the irrelevant numbers in each removed.

Figure 1
Figure 2

Input the input contains data for one to thirty boards, followed by a final line containing only the integer-1. The data for a board starts with a-line containing a single positive integer n, 4 <= n <=, and which is the number of Rows in this board. This is followed by n rows of data. Each row contains n single digits, 0-9, with no spaces between them.

Output the output consists of one to each board, containing a single integer, which are the number of paths from the Upper left corner to the lower right corner. There is fewer than 2 paths for any board.

Sample Input

4
2331
1213
1231
3110
4
3332
1213
1232
2120
5
11101
01111
11111
11101
11101
-1

Sample Output

3
0
7

Hint Brute force methods examining every path would likely exceed the allotted time limit. 64-bit integer values are AVA Ilable as long values in Java or long long values using the contest ' s/C + + compilers.   is to give you a maze, and then each lattice has a number, to the value of the time you want to jump the corresponding steps, but can not jump out of the maze of the range, deep search is easy to time out, this introduction DP, direct seconds to kill, jump to the lattice, to jump to the grid corresponding value directly plus, the last one just Code: #include <stdio.h> #include <string.h> char map[55][55]; int n; __int64 NUM[50][50]; int main () {int i,j,k; while (scanf ("%d", &n), N!=-1) {for (i=0;i<n;i++) scanf ("%s", Map[i]); Memset (Num,0,sizeof ( num)); Num[0][0]=1; for (i=0;i<n;i++) for (j=0;j<n;j++) {k=map[i][j]-' 0 '; if (k==0) continue; if (j+k<n) num[i][j+k]+=num[i][j]; if ( i+k<n) Num[i+k][j]+=num[i][j]; printf ("%i64d\n", num[n-1][n-1]); return 0; }

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.