Go home |
time limit:1000 MS |
memory limit:32768 K |
total submit:35 (9 users) |
Total accepted:10 (8 users) |
RATING:  |
special judge: no |
  |
Description |
In winter vacation, we often meet classmates, Ikki is no exception. The city where the Ikki is located can be seen as a square layout, divided into n*n small square area. Ikki every meeting place is in the northwest corner of the city, the square (N,n) represents the location, while the home is located in the southeast corner of the city, i.e. (a) of the location. As there are many routes to choose from, Ikki wants to go home every time the route are not the same, and Ikki want to be closer to home after each region, specifically: If Ikki is going from Zone A to area B, it must meet The minimum time required to get home from the B zone is less than the minimum time to get home from the a area. Now Ikki want to know how many different routes to go home. |
Input |
The first behavior of each group of data is an integer n (2<=n<=50), followed by n lines, each row has n integers (1<=m<=50), each of which represents the time taken to pass through the area, and it takes time to notice the start and end areas. |
Output |
The total number of different routes for each set of data output (less than 2^63). |
Sample Input |
3 1 1 1 1 1 1 1 1 1 3 1 2 3 1 2 3 1 2 3 |
Sample Output |
6 1 |
Author |
Eric @hrbust |
Why do Chinese questions have to be said in the question? Because this problem is easy to understand wrong.
The main idea: from one point to another point can go to the premise is: The current point to the end of the distance, greater than the point to go to the end of the distance, just line.
Idea: Since it is to have just said that a restrictive condition, we can go forward, spicy do not want to think, first reverse thinking, the end to all other points of the minimum distance. So we have all the points to the end of the distance. Then write again BFS, add the number of cases can go, you can.
AC Code:
#include <stdio.h> #include <queue> #include <string.h>using namespace std; #define LL Long longstruct zuobiao{int x,y,output; friend bool operator < (Zuobiao A,zuobiao b) {return a.output>b.output; }}now,nex;int n;int a[55][55];int dis[55][55];int vis[55][55];ll ans[55][55];int fx[4]={0,0,1,-1};int fy[4]={1,-1,0,0 };void BFS (int x,int y) {memset (dis,0,sizeof (dis)); Now.x=x; Now.y=y; Now.output=a[x][y]; priority_queue<zuobiao>s; Dis[x][y]=a[x][y]; S.push (now); while (!s.empty ()) {now=s.top (); S.pop (); for (int i=0;i<4;i++) {nex.x=now.x+fx[i]; Nex.y=now.y+fy[i]; if (nex.x>=0&&nex.x<n&&nex.y>=0&&nex.y<n&&dis[nex.x][nex.y]==0) { DIS[NEX.X][NEX.Y]=DIS[NOW.X][NOW.Y]+A[NEX.X][NEX.Y]; NEX.OUTPUT=DIS[NEX.X][NEX.Y]; S.push (NEX); }}}}void BFS2 (int X,int y) {memset (vis,0,sizeof (VIS)); memset (ans,0,sizeof (ans)); priority_queue<zuobiao>s; Now.x=x; Now.y=y; Now.output=dis[x][y]; S.push (now); Vis[x][y]=1; Ans[x][y]=1; while (!s.empty ()) {now=s.top (); S.pop (); for (int i=0;i<4;i++) {nex.x=now.x+fx[i]; Nex.y=now.y+fy[i]; NEX.OUTPUT=DIS[NEX.X][NEX.Y]; if (nex.x>=0&&nex.x<n&&nex.y>=0&&nex.y<n) {if (Dis[nex.x][nex . y]>now.output) {ANS[NEX.X][NEX.Y]+=ANS[NOW.X][NOW.Y]; if (vis[nex.x][nex.y]) continue; Vis[nex.x][nex.y]=1; S.push (NEX); }}}} printf ("%lld\n", Ans[0][0]);} int main () {while (~SCANF ("%d", &n)} {for (int. i=0;i<n;i++) {for (int j=0;j<n;j++) {scanf ("%d", &a[I][J]); }} BFS (n-1,n-1); BFS2 (n-1,n-1); } return 0;}
hrbust/Harbin Science and technology OJ 1617 back home "Bfs+bfs"