Walk the Campus
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total Submission (s): 3360 Accepted Submission (s): 1009
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 The first behavior of each group of test data N (2=<n<=50), the next n rows have n number of rows per row, representing the time spent in each region T (0<T<=50) (because the bedroom and the room are on the third floor, so the starting point and the end will be time-consuming).
Output for each set of test data, the total number of routes is output (less than 2^63).
Sample Input
31 2 31 2 31 2 331 1 11 1 11 1 1
Sample Output
16
Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1428
Title Analysis: and HDU 1142 similar, but this question is to point right, or request the shortest way, with BFS search, each point to the lower right corner of the most short-circuit, and then the number of memory search
#include <cstdio> #include <cstring> #include <queue> #define LL long long using namespace Std;int const M AX = 55;int Dis[max][max], map[max][max];ll dp[max][max];int n;int dx[4] = {1, 0,-1, 0};int dy[4] = {0,-1, 0, 1};struct node{int x, y;}; void BFS () {queue <NODE> q; NODE St; St.x = n; ST.Y = n; Dis[n][n] = Map[n][n]; Q.push (ST); while (!q.empty ()) {NODE cur = q.front (), t; Q.pop (); for (int i = 0; i < 4; i++) {t.x = cur.x + dx[i]; T.y = Cur.y + dy[i]; if (T.x < 1 | | T.y < 1 | | t.x > N | | t.y > N) continue; if (Dis[t.x][t.y] > Dis[cur.x][cur.y] + map[t.x][t.y] | | dis[t.x][t.y] = =-1) {DIS[T.X][T.Y] = Dis[cur.x][cur.y] + MAP[T.X][T.Y]; Q.push (t); }}}}ll DFS (int x, int y) {if (Dp[x][y]) return dp[x][y]; if (x = = N && y = = n) return 1; LL TMP= 0; for (int i = 0; i < 4; i++) {int xx = x + dx[i]; int yy = y + dy[i]; if (xx > N | | yy > N | | xx < 1 | | yy < 1 | | dis[xx][yy] >= dis[x][y]) continue; TMP + = DFS (xx, yy); } return Dp[x][y] = tmp;} int main () {while (scanf ("%d", &n)! = EOF) {memset (DIS,-1, sizeof (DIS)); memset (DP, 0, sizeof (DP)); for (int i = 1; I <= n; i++) for (int j = 1; J <= N; j + +) scanf ("%d", &map[i][j]); BFS (); printf ("%i64d\n", DFS (1, 1)); }}
HDU 1428 Stroll Campus (BFS + memory Search)