HDU 1428漫步校园
漫步校园
#include<iostream>
#include<stdio.h>
#include<queue>
#include<algorithm>
#include<stdlib.h>
#include<cstring>
#define ll long long
using namespace std;
int n;
ll mp[][],dis[][];
int addx[]={,,-,,},addy[]={,,,,-};
int have[][];
ll f[][];
void spfa(int starx,int stary){
queue<int> xx,yy;
while(!xx.empty()) xx.pop();
while(!yy.empty()) yy.pop();
xx.push(starx);
yy.push(stary);
dis[starx][stary]=mp[starx][stary],have[starx][stary]=;
while(!xx.empty()){
int nowx=xx.front();
int nowy=yy.front();
xx.pop(),yy.pop();
have[nowx][nowy]=;
for(int i=;i<=;i++){
int tox=nowx+addx[i],toy=nowy+addy[i];
if(tox<=||tox>n||toy>n||toy<=) continue;
if(dis[tox][toy]>dis[nowx][nowy]+mp[tox][toy])
{
dis[tox][toy]=dis[nowx][nowy]+mp[tox][toy];
//printf("nowx=%d nowy=%d tox=%d toy=%d\n",nowx,nowy,tox,toy);
//printf("dis[nowx][nowy]=%d dis[tox][toy]=%d mp[tox][toy]=%d\n",dis[nowx][nowy],dis[tox][toy],mp[tox][toy]);
if(have[tox][toy]==){
xx.push(tox);
yy.push(toy);
have[tox][toy]=;
}
}
}
}
}
void cl(){
memset(mp,,sizeof(mp));
memset(f,,sizeof(f));
memset(have,,sizeof(have));
memset(dis,,sizeof(dis));
}
ll dp(int x,int y){
if(f[x][y]) return f[x][y];
if(x==n&&y==n) return ;
ll now=;
for(int i=;i<=;i++){
int tox=x+addx[i];
int toy=y+addy[i];
if(tox<=||tox>n||toy>n||toy<=) continue;
if(dis[tox][toy]<dis[x][y]) now+=dp(tox,toy);
}
return f[x][y]=now;
}
int main(){
while(scanf("%d",&n)!=EOF){
cl();
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
cin>>mp[i][j];
spfa(n,n);
printf("%lld\n",dp(,));
}
}
HDU 1428漫步校园的更多相关文章
- [HDU 1428]--漫步校园(记忆化搜索)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1428 漫步校园 Time Limit: 2000/1000 MS (Java/Others) M ...
- HDU 1428 漫步校园(记忆化搜索,BFS, DFS)
漫步校园 http://acm.hdu.edu.cn/showproblem.php?pid=1428 Problem Description LL最近沉迷于AC不能自拔,每天寝室.机房两点一线.由于 ...
- HDU 1428 漫步校园 (BFS+优先队列+记忆化搜索)
题目地址:HDU 1428 先用BFS+优先队列求出全部点到机房的最短距离.然后用记忆化搜索去搜. 代码例如以下: #include <iostream> #include <str ...
- hdu 1428 漫步校园
http://acm.hdu.edu.cn/showproblem.php?pid=1428 dijstra+dp; #include <cstdio> #include <queu ...
- HDOJ 1428 漫步校园
漫步校园 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- 搜索专题: HDU1428漫步校园
漫步校园 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- Hdu428 漫步校园 2017-01-18 17:43 88人阅读 评论(0) 收藏
漫步校园 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submissi ...
- HDU 1428
漫步校园 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- hdu 1428(很好的一道题,最短路+记忆化搜索)
漫步校园 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
随机推荐
- (一)分布式数据库tidb-简介
因为数据磁盘问题,最近进行了更换库,所以决定写关于这方面的专题的博客,博客信息参考的官方文档. 一.分布式数据库使用背景 随着互联网的飞速发展,业务量可能在短短的时间内爆发式地增长,对应的数据量可能快 ...
- .NetCore技术研究-ConfigurationManager在单元测试下的坑
最近在将原有代码迁移.NET Core, 代码的迁移基本很快,当然也遇到了不少坑,重构了不少,后续逐步总结分享给大家.今天总结分享一下ConfigurationManager遇到的一个问题. 先说一下 ...
- 上海地铁游移动APP需求分析
人们在现实的生活中会遇到各种各样的问题,有不同的需求,我们需要加以解决,开发一个软件是一个很好的方法去解决这些需求和问题.那么,作为一个软件团队如何才能准确而全面地找到这些需求呢?主要有一下几个步骤. ...
- python django+bootstrap4+mysql智慧交通系统构建
之前,我做了一个实训的项目,但是一直没有展示如何做的,现在就让我讲解一下如何用django+bootstrap4+mysql实现这个智慧交通系统.这里用到的是网页的bootstrap4框架和mysql ...
- ZooKeeper 介绍及集群环境搭建
本篇由鄙人学习ZooKeeper亲自整理的一些资料 包括:ZooKeeper的介绍,我们要学习ZooKeeper的话,首先就要知道他是干嘛的对吧. 其次教大家如何去安装这个精巧的智慧品! 相信你能研究 ...
- 新版本SpringCloud sleuth整合zipkin
SpringCloud Sleuth 简介 Spring Cloud Sleuth为Spring Cloud实现了分布式跟踪解决方案. Spring Cloud Sleuth借鉴了Dapper的术语. ...
- 数据结构慕课PTA 05-树9 Huffman Codes
题目内容 In 1953, David A. Huffman published his paper "A Method for the Construction of Minimum-Re ...
- ReactNative之Redux详解
用redux有一段时间了,感觉还是有必要把其相关的知识点系统的总结一下的,毕竟好记性不如烂笔头.上篇博客更新了关于<ES6中的迭代器.Generator函数以及Generator函数的异步操作& ...
- Java 截取字符串中指定数据及之后数据
String resCallBackJson="12556{1{{{456858585{"; resCallBackJson = resCallBackJson.su ...
- 腾讯、阿里、百度、360、114 公共DNS分享
DNS,在互联网有着重要的地位,域名转换成IP,都是DNS在工作. 腾讯 DNS+ IP:119.29.29.29 备用:182.254.116.116 阿里DNS ip:223.5.5.5 223. ...