hdu1428漫步校园
#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漫步校园的更多相关文章
- 搜索专题: HDU1428漫步校园
漫步校园 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- hdu1428漫步校园( 最短路+BFS(优先队列)+记忆化搜索(DFS))
Problem Description LL最近沉迷于AC不能自拔,每天寝室.机房两点一线.由于长时间坐在电脑边,缺乏运动.他决定充分利用每次从寝室到机房的时间,在校园里散散步.整个HDU校园呈方形布 ...
- HDOJ 1428 漫步校园
漫步校园 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU 1428 漫步校园(记忆化搜索,BFS, DFS)
漫步校园 http://acm.hdu.edu.cn/showproblem.php?pid=1428 Problem Description LL最近沉迷于AC不能自拔,每天寝室.机房两点一线.由于 ...
- [HDU 1428]--漫步校园(记忆化搜索)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1428 漫步校园 Time Limit: 2000/1000 MS (Java/Others) M ...
- Hdu428 漫步校园 2017-01-18 17:43 88人阅读 评论(0) 收藏
漫步校园 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submissi ...
- HDU 1428漫步校园
漫步校园 Problem Description LL最近沉迷于AC不能自拔,每天寝室.机房两点一线.由于长时间坐在电脑边,缺乏运动.他决定充分利用每次从寝室到机房的时间,在校园里散散步.整个HDU校 ...
- hdu 1428 漫步校园
http://acm.hdu.edu.cn/showproblem.php?pid=1428 dijstra+dp; #include <cstdio> #include <queu ...
- HDU 1428 漫步校园 (BFS+优先队列+记忆化搜索)
题目地址:HDU 1428 先用BFS+优先队列求出全部点到机房的最短距离.然后用记忆化搜索去搜. 代码例如以下: #include <iostream> #include <str ...
随机推荐
- Laravel 调试器 Debugbar 和数据库导出利器 DbExporter 扩展安装及注意事项
一.Debugbar安装 参考:Laravel 调试利器 —— Laravel Debugbar 扩展包安装及使用教程 的“2.安装”部分 二.DbExporter安装 参考:Laravel 扩展推荐 ...
- C# 数组 随机 排序
]; ; i < ; i++) { arrInt[i] = i; } arrInt = arrInt.OrderBy(c => Guid.NewGuid()).ToArray<int ...
- uoj#35 后缀排序(后缀数组模版)
#include<bits/stdc++.h> #define N 100005 using namespace std; char s[N]; int a[N],c[N],t1[N],t ...
- Ta-Lib用法介绍 !
一.函数索引 重叠研究 BBANDS Bollinger Bands DEMA Double Exponential Moving Average EMA Exponential Moving Ave ...
- Power BI连接至Amazon Redshift
一直在使用Power BI连接至MongoDB中,但效果一直不是太理想,今天使用另一种方法,将MongoDB中的数据通过Azure Data Factory转入Amazon Redshift中,而在P ...
- 解析 Qt 程序在Windows 下发布
原文请看:http://www.cnblogs.com/elect-fans/archive/2012/03/15/2408579.html Qt 程序在Windows下发布是本文要介绍的内容,不多说 ...
- centos python 安装 readability
yum install libxslt-devel pip install readability-lxml
- codis 的dashboard服务无法启动 提示pid已经运行
ps -rf|grep pid号 ,一直查询不到,进程并没有运行, 后来在Zookeeper中发现get /zk/codis/db_gdata/dashboard 这个中存在着pid,连接到zooke ...
- Eclipse - Tasks介绍
完整的过程 1.1.新定义标签 位置:Window —— Preferences —— Java —— Compiler —— Task Tags —— New 说明: 默认的任务标签有三个FIXME ...
- 洛谷——P2708 硬币翻转
P2708 硬币翻转 题目背景 难度系数:☆☆☆☆☆(如果你看懂了) 题目描述 从前有很多个硬币摆在一行,有正面朝上的,也有背面朝上的.正面朝上的用1表示,背面朝上的用0表示.现在要求从这行的第一个硬 ...