Title Link:http://gdutcode.sinaapp.com/problem.php?cid=1031&pid=2
The problem is to find the path of symmetry, then the hard obvious can be the lower right corner of each block added to the upper left corner corresponding to each block. Then it becomes the number of the shortest path from the upper left corner to the diagonal.
Run first. The shortest path obtains the shortest path of p (i, J) from the starting point to (i, J) .
Then it is the number of shortest paths to find. Obviously CNT (i, J) is the and of its surrounding points that can pass through the shortest path to its cnt . This can be done using a memory search.
Code:
#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<cstring>#include<algorithm>#include<Set>#include<map>#include<queue>#include<vector>#include<string>#defineLL Long Long#defineMOD 1000000009using namespacestd;Const intMAXN = the;intXx[] = {-1,1,0,0};intYy[] = {0,0, -1,1};intN, A[maxn][maxn], MI;intP[MAXN][MAXN];intCNT[MAXN][MAXN];BOOLvis[maxn*MAXN];voidinput () {scanf ("%d", &N); for(inti =0; I < n; ++i) for(intj =0; J < N; ++j) scanf ("%d", &A[i][j]); for(inti =0; I < n; ++i) for(intj =0; J < N; ++j)if(I+j! = N1) A[i][j]+ = a[n-1-j][n-1-i]; Memset (P,-1,sizeof(p)); memset (Vis,false,sizeof(Vis));}voidcal () {intk, x, Y, ix, iy; Queue<int>Q; p[0][0] = a[0][0]; Q.push (0); vis[0] =true; while(!Q.empty ()) {k=Q.front (); Q.pop (); VIS[K]=false; X= k/ -; Y= k% -; for(inti =0; I <4; ++i) {IX= x+Xx[i]; Iy= y+Yy[i]; if(Ix+iy > N-1|| IX <0|| Iy <0)Continue; if(P[ix][iy] = =-1|| P[ix][iy] > p[x][y]+A[ix][iy]) {P[ix][iy]= p[x][y]+A[ix][iy]; if(!vis[ -*ix+iy]) {Q.push ( -*ix+iy); vis[ -*ix+iy] =true; } }}} mi= p[0][n-1]; for(inti =0; I < n; ++i) Mi= Min (mi, p[i][n-1-i]);}intDfsintXinty) { if(Cnt[x][y]! =-1)returnCnt[x][y]; intIX, iy, all =0; for(inti =0; I <4; ++i) {IX= x+Xx[i]; Iy= y+Yy[i]; if(Ix+iy > N-1|| IX <0|| Iy <0)Continue; if(P[ix][iy]+a[x][y] = =P[x][y]) all= (All+dfs (ix, iy))%MOD; } Cnt[x][y]=All ; returnAll ;}voidWork () {cal (); memset (CNT,-1,sizeof(CNT)); cnt[0][0] =1; intAns =0; for(inti =0; I < n; ++i)if(mi = = p[i][n-1-i]) ans= (Ans+dfs (i, n1-i))%MOD; printf ("%d\n", ans);}intMain () {//freopen ("test.in", "R", stdin); intT; scanf ("%d", &T); for(intTimes =1; Times <= T; ++Times ) {input (); Work (); } return 0;}View Code
ACM Learning Process-Guangdong University of Technology 2016 final-online game C Wintermelon's Magic World Quest (Shortest way && recursion)