#include <queue>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <cstdio> using namespace std;
int n;
const int maxn = 60;
const int INF = 0x7fffffff; struct node {
int x, y;
int d;
int mind;
};
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0}; node map[maxn][maxn];
queue<node> Q;
long long vis[maxn][maxn]; void input()
{
while(!Q.empty()) {
Q.pop();
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
scanf("%d", &map[i][j].d);
map[i][j].mind = INF;
map[i][j].x = i;
map[i][j].y = j;
}
}
} void bfs()
{
node tmp, next;
tmp.d = map[n][n].d;
tmp.x = n;
tmp.y = n;
tmp.mind = map[n][n].d;
map[n][n].mind = map[n][n].d;//init the beginning
Q.push(tmp);
while(!Q.empty())
{
node now = Q.front();
Q.pop();
for(int i = 0; i < 4; i++) {
next.x = now.x + dx[i];
next.y = now.y + dy[i];
if(next.x<1 || next.x>n || next.y<1 || next.y>n) continue;
if(map[next.x][next.y].mind > map[now.x][now.y].mind + map[next.x][next.y].d) {
map[next.x][next.y].mind = map[now.x][now.y].mind + map[next.x][next.y].d;
Q.push(map[next.x][next.y]);
}
}
}
} long long dfs(int x, int y) //int wa
{
if(x==n && y==n) return 1;
if(vis[x][y]) return vis[x][y];
int newx, newy;
for(int i = 0; i < 4; i++) {
newx = x + dx[i];
newy = y + dy[i];
if(newx < 1 || newx > n || newy < 1 || newy > n) continue;
if(map[x][y].mind > map[newx][newy].mind) {
vis[x][y] += dfs(newx, newy);
}
}
return vis[x][y];
} int main()
{
while(scanf("%d", &n) != EOF) {
input();
bfs();
memset(vis, 0, sizeof(vis));
long long res = dfs(1, 1);
cout << res << endl;
}
return 0;
}

最新文章

  1. 一款强大的Android网络渗透软件dsploit
  2. jQuery打造智能提示插件
  3. win10启动无法进入桌面
  4. Fragment的使用(一)
  5. Nodejs学习(四)- express目录的分析
  6. IDEA 配置 tomcat 启动内存
  7. ffmpeg处理RTMP流媒体的命令 发送流媒体的命令(UDP,RTP,RTMP)
  8. SQLNestedException: Cannot create JDBC driver of class &#39;&#39; for connect URL &#39;null&#39; 解决办法
  9. lsslot
  10. disucz!NT 3.5.0 验证码点击不能变化只是样式变化
  11. linux上应用程序的执行机制
  12. Android 签名(5)用命令签名和用IDE签名
  13. Hbase对hive的支持没有hdfs的好的原因 及hbase什么时候使用 及rowkey设计技巧
  14. 使用Jquery后去div个数
  15. Java对于特殊字符做间隔读入的处理(1.3.4)
  16. webpack学习(六)打包压缩js和css
  17. JAVA_新建一个方法并且求三个数中的最大值
  18. 4.2模拟赛 wormhole(期望DP Dijkstra)
  19. Spring Cloud 与 Dubbo、Spring Cloud 与 Docker、Spring Cloud 与 Kubernetes 比较
  20. 4.SSM配置shiro权限管理

热门文章

  1. Linux System.map文件【转】
  2. 定制LFS镜像及安装过程
  3. python 判断文件的创建时间和当前时间的比较
  4. 【bzoj1026】windy数
  5. 小程序2(JSSDK,ECS搭建ftp服务器)
  6. NOIP 2012 Day1
  7. LeetCode解题报告—— Unique Binary Search Trees &amp; Binary Tree Level Order Traversal &amp; Binary Tree Zigzag Level Order Traversal
  8. 寻找与网页内容相关的图片(三)网易新闻与qq空间的做法
  9. nginx安装及配置文件详解
  10. VS Code开发技巧集锦