#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. TCP的3次握手/4次握手

    三次握手: 在TCP/IP协议中,TCP协议提供可靠的连接服务,采用三次握手建立一个连接,如图下所示: (1) 第一次握手:建立连接时,客户端A发送SYN包(SYN=j)到服务器B,并进入SYN_SE ...

  2. LCD 每隔10分钟 自动熄灭 --打开Framebuffer console的时候【转】

    转自:http://blog.csdn.net/liujia2100/article/details/9009063 版权声明:本文为博主原创文章,未经博主允许不得转载. 之前移植LCD的时候,一切正 ...

  3. 运输层和TCP/IP协议

    0. 基本要点 运输层是为相互通信的应用进程提供逻辑通信. 端口和套接字的意义 什么是无连接UDP 什么是面向连接的TCP 在不可靠的网络上实现可靠传输的工作原理,停止等待协议和ARQ协议 TCP的滑 ...

  4. c#中char、string转换为十六进制byte的浅析

    问题引出: string转换为byte(十六进制) static void Main(string[] args) { "; byte[] b = Encoding.Default.GetB ...

  5. 微信支付之SHA256签名失败

    在接微信支付的时候,或多或少会遇到签名失败,本人接入的时候也遇了不少次: 总结如下: 1.参数没有经过ASCII排序 2.参数包含中文未经过UTF-8标准转化加密后的签名不对应(经本人测验:加密算法要 ...

  6. spring restTemplate 用法

    发出get请求,方式一 String url = serverUrl+"/path/path?id={id}"; int i = restTemplate.getForObject ...

  7. Mycat 读写分离

    简介 Mycat 是 MySQL中间件,Mycat的原理中最重要的一个动词就是'拦截',它拦截了用户发送过来的SQL语句,首先对SQL语句做了一些特定的分析:如分片分析.路由分析.读写分离分析.缓存分 ...

  8. 【Java基础】一些问题

    1. HashSet是如何保证数据不重复的: 首先,HashSet添加元素的时候,底层是通过HashMap的put方法来实现的,而添加的元素,则是保存在了hashMap的key里,因为HashMap的 ...

  9. linux命令(7):ipcs/ipcrm命令

    ipcs作用 :查看消息队列(ipcs –q).共享内存(ipcs –m).信号灯(ipcs -s) ipcrm作用 :删除消息队列.共享内存.信号灯 ipcrm使用方式: ipcrm [ -M ke ...

  10. mysql 主从 同步原理及配置

    一.在mssql 里头实现同步镜像,只能主库用而镜像库不能同时用,而mysql 主从同步可以实现 数据库的读写分离,主库负责 update insert delete ,从库负责select 这样一来 ...