#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. C/C++中手动获取调用堆栈【转】

    转自:http://blog.csdn.net/kevinlynx/article/details/39269507 版权声明:本文为博主原创文章,未经博主允许不得转载. 当我们的程序core掉之后, ...

  2. TCP之listen&backlog

    1. listen函数: #include <sys/socket.h> int listen(int sockfd, int backlog); ret-成功返回0 失败返回- list ...

  3. SourceTree 过期,注册导入许可证

    参考这里:SourceTree过期,需要注册导入 SourceTree License 许可证 很详细 补充: 如果在 SourceTree 软件里注册失败,可以在网页注册. 如果其他邮箱不支持,可以 ...

  4. Laravel 5.2 四、.env 文件与模型操作

    一..env文件 .env 文件是应用的环境配置文件,在配置应用参数.数据库连接.缓存处理时都会使用这个文件. // 应用相关参数 APP_ENV=local APP_DEBUG=true //应用调 ...

  5. 机器学习开源项目精选TOP30

    本文共图文结合,建议阅读5分钟. 本文为大家带来了30个广受好评的机器学习开源项目. 640?wx_fmt=jpeg&wxfrom=5&wx_lazy=1 最近,Mybridge发布了 ...

  6. JVM监控常用命令行工具

    jps jps -mlv //列出正在运行的虚拟机进程 jstat jstat -gc pid //监视java堆状况 显示列名 具体描述 S0C 年轻代中第一个survivor(幸存区)的容量 (字 ...

  7. LeetCode解题报告—— Regular Expression Matching

    Given an input string (s) and a pattern (p), implement regular expression matching with support for  ...

  8. [loj#2566][BZOJ5333] [Sdoi2018]荣誉称号 树形dp

    #2566. 「SDOI2018」荣誉称号   休闲游戏玩家小 Q 不仅在算法竞赛方面取得了优异的成绩,还在一款收集钻石的游戏中排名很高. 这款游戏一共有 n 种不同类别的钻石,编号依次为 1 到 n ...

  9. AC日记——红色的幻想乡 洛谷 P3801

    红色的幻想乡 思路: 线段树+容斥原理: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 #de ...

  10. C++中正确使用PRId64

    http://blog.csdn.net/win_lin/article/details/7912693