Title Address: HDU 1428
First use the bfs+ priority queue to find the shortest distance from all points to the computer room, and then use the memory search.
The code is as follows:
#include <iostream>#include <string.h>#include <math.h>#include <queue>#include <algorithm>#include <stdlib.h>#include <map>#include <set>#include <stdio.h>using namespace STD;#define LL __int64#define PI ACOs ( -1.0)Const intMod=1e9+7;Const intinf=0x3f3f3f3f;Const Doubleeqs=1e-9;Const intmaxn= -+Ten;intD[MAXN][MAXN], MP[MAXN][MAXN], VIS[MAXN][MAXN], N; LL DP[MAXN][MAXN];intjx[]={0,0,1,-1};intjy[]={1,-1,0,0};structnode{intx, y, step;BOOL operator< (ConstNode &tmp)Const{returntmp.step<step; }};voidBFS () {node f1, F2; f1.x=n-1; f1.y=n-1; f1.step=mp[n-1][n-1]; d[n-1][n-1]=mp[n-1][n-1]; vis[n-1][n-1]=1; priority_queue<node>q; Q.push (F1); while(!q.empty ()) {f1=q.top (); Q.pop (); for(intI=0;i<4; i++) {f2.x=f1.x+jx[i]; F2.y=f1.y+jy[i];if(f2.x>=0&&f2.x<n&&f2.y>=0&&F2.Y<N&&!VIS[F2.X][F2.Y]) {vis[f2.x][f2.y]=1; F2.STEP=F1.STEP+MP[F2.X][F2.Y]; D[f2.x][f2.y]=f2.step; Q.push (F2); }}}}ll Dfs (intXintY) {intI, a, b;if(Dp[x][y])returnDp[x][y]; for(i=0;i<4; i++) {a=x+jx[i]; B=y+jy[i];if(a>=0&&a<n&&b>=0&&b<n&&d[a][b]<d[x][y]) {Dp[x][y]+=dfs (A, b); } }returnDp[x][y];}intMain () {intI, J; while(scanf("%d", &n)!=eof) { for(i=0; i<n;i++) { for(j=0; j<n;j++) {scanf("%d", &mp[i][j]); } }memset(DP,0,sizeof(DP));memset(Vis,0,sizeof(VIS)); BFS (); dp[n-1][n-1]=1;printf("%i64d\n", DFS (0,0)); }return 0;}
HDU 1428 Stroll Campus (bfs+ priority queue + memory Search)