hdu--1428--Stroll Campus-search/Shortest Path/memory search

Source: Internet
Author: User

Walk the CampusTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others) Total Submission (s): 3121 Accepted Submission (s): 945

Problem DESCRIPTIONLL recently addicted to AC extricate oneself, every day bedroom, room 2.1 line. Lack of exercise because of sitting on the computer for a long time. He decided to take full advantage of every time from the bedroom to the computer room to take a walk on campus. The entire HDU campus is a square layout that can be divided into n*n squares, representing each area. For example, I will live in the 18th dormitory located in the northwest corner of the campus, that is, the square (a quarter) representative of the place, and the room is located in the third laboratory building in the southeast End (N,n). Because there are many routes to choose from, LL hope to take a different route each time. In addition, he considered from the a area to the B area only when there is a route from B to the machine room is closer than any one from a to the computer room (otherwise it may never be able to go to the engine room ...). What he wants to know now is how many lines there are to meet the requirements. Can you tell him?

Input each set of test data of the first behavior N (2=<n<=50), the next n rows have n number per row, representing the time elapsed through each region T (0&LT;T&LT;=50) (because the bedroom and room are on the third floor, so the starting point and the end will be time-consuming).

Output outputs the total number of routes (less than 2^63) for each set of test data.

Sample Input
31 2 31 2 31 2 331 1 11 1 11 1 1

Sample Output
16
Hemp Online you hateful beast, test instructions is not good to write, the pit of the father 1 years ago to now has not a drop it, only blame me too young too patriotic, can not understand the connotation of foreign language


Test instructions: give you nxn map, from the upper left corner to the lower right corner of the number of routes (it is 2^63,int not fit oh ... )

Analysis: Highlighting * * * * * is not the shortest path of the number of routes, n more people is the pit here, can go from a to B condition: A to the lower right corner of the shortest distance is greater than B to the lower right corner of the distance, so a start from the bottom right to a wide search record it to all points of the shortest distance, and Follow the lines that are descending on record values.


#include <iostream> #include <cstdio> #include <cstring> #include <queue> #define MM (A, B) a <b?b:ausing namespaceStd;intN,Dd[4][2]={1,0,-1,0,0,1,0,-1},Map[ -][ -];//map: This map of the inputintVis[ -][ -],Map[ -][ -];//map: Shortest path map from (n-1,n-1) to all points__int64S[ -][ -],Num[ -][ -];structNode{intX,Y;}Ss;Queue<Node>Q,Qq;voidBFs()//Production (n-1,n-1) to all points of the shortest map, if not, then you can go to the excrement.intI,J,K,L,X,Xx,Y,Yy;Memset(Map,0,sizeof(Map));Q=Qq;Ss.X=Ss.Y=N-1;Map[N-1][N-1]=Map[N-1][N-1];Q.Push(Ss); while(Q.Size())    {Ss=Q.Front();Q.Pop();X=Ss.X;Y=Ss.Y; for(I=0;I<4;I++) {Xx=X+Dd[I][0];Yy=Y+Dd[I][1];if(Xx>=0&&Yy>=0&&Xx<N&&Yy<N&& (Map[Xx][Yy]==0||Map[Xx][Yy]>Map[X][Y]+Map[Xx][Yy]))            {Map[Xx][Yy]=Map[X][Y]+Map[Xx][Yy];Ss.X=Xx;Ss.Y=Yy;Q.Push(Ss); }        }    }}__int64Dfs(intX,intY)//Search by condition {intI,J,K,L,X,Y;__int64Sum=0;if(S[X][Y])returnS[X][Y]; /  /memory path point reduction repeat search for(I=0;I<4;I++) {X=X+Dd[I][0];Y=Y+Dd[I][1];if(X>=0&&X<N&&Y>=0&&Y<N&&Map[X][Y]<Map[X][Y])//Minimum Path value decrement {S[X][Y]+=Dfs(X,Y);//Search and record the current point of information for the memory search, the next time you find this can return the value directly}}returnS[X][Y];}intMain (void){intI,J,K,L; while(scanf("%d",&N)!=Eof)    { for(I=0;I<N;I++) for(J=0;J<N;J++) {scanf("%d",&Map[I][J]); }Memset(Vis,0,sizeof(Vis));Memset(S,0,sizeof(S));S[N-1][N-1]=1;BFs();Dfs(0,0);Printf("%i64d\n",S[0][0]); }return0;}
Summary: Boring problem, the question is really hateful, this pit than by sister refused to confess still uncomfortable ah ~ ~


hdu--1428--Stroll Campus-search/Shortest Path/memory search

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.