#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;
}

hdu1428漫步校园的更多相关文章

  1. 搜索专题: HDU1428漫步校园

    漫步校园 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  2. hdu1428漫步校园( 最短路+BFS(优先队列)+记忆化搜索(DFS))

    Problem Description LL最近沉迷于AC不能自拔,每天寝室.机房两点一线.由于长时间坐在电脑边,缺乏运动.他决定充分利用每次从寝室到机房的时间,在校园里散散步.整个HDU校园呈方形布 ...

  3. HDOJ 1428 漫步校园

    漫步校园 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  4. HDU 1428 漫步校园(记忆化搜索,BFS, DFS)

    漫步校园 http://acm.hdu.edu.cn/showproblem.php?pid=1428 Problem Description LL最近沉迷于AC不能自拔,每天寝室.机房两点一线.由于 ...

  5. [HDU 1428]--漫步校园(记忆化搜索)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1428 漫步校园 Time Limit: 2000/1000 MS (Java/Others)    M ...

  6. Hdu428 漫步校园 2017-01-18 17:43 88人阅读 评论(0) 收藏

    漫步校园 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submissi ...

  7. HDU 1428漫步校园

    漫步校园 Problem Description LL最近沉迷于AC不能自拔,每天寝室.机房两点一线.由于长时间坐在电脑边,缺乏运动.他决定充分利用每次从寝室到机房的时间,在校园里散散步.整个HDU校 ...

  8. hdu 1428 漫步校园

    http://acm.hdu.edu.cn/showproblem.php?pid=1428 dijstra+dp; #include <cstdio> #include <queu ...

  9. HDU 1428 漫步校园 (BFS+优先队列+记忆化搜索)

    题目地址:HDU 1428 先用BFS+优先队列求出全部点到机房的最短距离.然后用记忆化搜索去搜. 代码例如以下: #include <iostream> #include <str ...

随机推荐

  1. HDU 5136 Yue Fei's Battle

    题目链接:HDU-5136 网上的一篇题解非常好,所以就直接转载了.转自oilover的博客 代码: #include<cstring> #include<cstdio> #i ...

  2. 手机端GPS定位结合百度地图实现定位

    html页面: <!DOCTYPE html>  <html>  <head>      <meta http-equiv="Content-Typ ...

  3. Nginx-进程模型

    1.整体框架 正常执行起来的Nginx有很多进程,有master_process和worker_process进程,master_process是监控进程即主线程,worker_process是工作进 ...

  4. Mybatis插入数据返回自增主键

    方法有很多,参考 mysql函数之六:mysql插入数据后返回自增ID的方法,last_insert_id(),selectkey 这里记录一下工作中自己用到的selectkey方法的详细过程. po ...

  5. 详解WordPress中简码格式标签编写的基本方法

    WordPress 简码是一种类似于论坛标签的东西,格式类似于把尖括号换成中括号的 Html 标签.简码很多人叫做短代码,但官方的翻译应该是简码,在这里纠正一下. 简码的开发的逻辑比较简单,主要就是添 ...

  6. 在LoadRunner中转换字符串大小写的C语言函数

    在LoadRunner中转换字符串大小写的C语言函数 . loadrunner语言ccharacterstringaction 封装ConvertToXXX函数: //ConvertToUpper f ...

  7. 转:Google Project Zero挖洞经验整理

    https://www.sec-un.org/google-project-zero%E6%8C%96%E6%B4%9E%E7%BB%8F%E9%AA%8C%E6%95%B4%E7%90%86/ 1. ...

  8. Codeforces Round #426 (Div. 2) D The Bakery(线段树 DP)

     The Bakery time limit per test 2.5 seconds memory limit per test 256 megabytes input standard input ...

  9. python3下安装aiohttp遇到过的那些坑

    python3下安装aiohttp遇到过的那些坑 最近需要用到aiohttp这个库,在安装过程中遇到很多坑.google.baidu后,依然没有找到合适的解决方案. 后来通过去python官方的PyP ...

  10. 【爬虫】python requests模拟登录知乎

    需求:模拟登录知乎,因为知乎首页需要登录才可以查看,所以想爬知乎上的内容首先需要登录,那么问题来了,怎么用python进行模拟登录以及会遇到哪些问题? 前期准备: 环境:ubuntu,python2. ...