HDU 1428
漫步校园
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2183 Accepted Submission(s): 627
1 2 3
1 2 3
1 2 3
3
1 1 1
1 1 1
1 1 1
/* */
#include<stdio.h>
#include<iostream>
#include<cstdlib>
#include<queue>
using namespace std;
const int HH=(<<)-;
int f[][];
__int64 val[][];
int dis[][];
bool in_Queue[][];
int map[][]={{,},{,},{-,},{,-}};
int n;
struct node
{
int x;
int y;
};
void bfs()
{
int i,x1,y1;
node tmp,tmp2;
queue<node>q;
tmp.x=tmp.y=n;
q.push(tmp);
dis[n][n]=n;
// memset(in_Queue,false,sizeof(in_Queue));
// in_Queue[n][n]=true;
while(q.size()>)
{
tmp=q.front();
q.pop();
// in_Queue[tmp.x][tmp.y]=false;
for(i=;i<;i++)
{
x1=tmp.x+map[i][];
y1=tmp.y+map[i][];
if(x1>=&&x1<=n && y1>=&&y1<=n)
if(dis[x1][y1]==HH||dis[x1][y1]>dis[tmp.x][tmp.y]+f[x1][y1])
{
dis[x1][y1]=dis[tmp.x][tmp.y]+f[x1][y1];
// if(in_Queue[x1][y1]==false)
{
tmp2=tmp;
tmp.x=x1;
tmp.y=y1;
q.push(tmp);
tmp=tmp2;
in_Queue[x1][y1]=true;
}
}
}
}
}
void ceshi()
{
int i,j;
for(i=;i<=n;i++)
{
printf("\n");
for(j=;j<=n;j++)
printf("%d ",dis[i][j]);
}
}
__int64 dfs(int x,int y)
{
int i,x1,y1;
__int64 sum=;
if(x==n && y==n) return ;
if(val[x][y]>) return val[x][y];
for(i=;i<;i++)
{
x1=x+map[i][];
y1=y+map[i][];
if(x1>=&&x1<=n && y1>=&&y1<=n)
{
if(dis[x][y]>dis[x1][y1])
sum+=dfs(x1,y1);
}
}
val[x][y]=sum;
return val[x][y];
} int main()
{
int i,j;
__int64 k;
while(scanf("%d",&n)>)
{
for(i=;i<=n;i++)
for(j=;j<=n;j++)
{
scanf("%d",&f[i][j]);
dis[i][j]=HH;
}
bfs();
memset(val,,sizeof(val));
// ceshi();
k=;
k=dfs(,);
printf("%I64d\n",k);
}
return ;
}
HDU 1428的更多相关文章
- HDU 1428 漫步校园 (BFS+优先队列+记忆化搜索)
题目地址:HDU 1428 先用BFS+优先队列求出全部点到机房的最短距离.然后用记忆化搜索去搜. 代码例如以下: #include <iostream> #include <str ...
- 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 dijstra+dp; #include <cstdio> #include <queu ...
- [HDU 1428]--漫步校园(记忆化搜索)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1428 漫步校园 Time Limit: 2000/1000 MS (Java/Others) M ...
- hdu 1428(很好的一道题,最短路+记忆化搜索)
漫步校园 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU 1428漫步校园
漫步校园 Problem Description LL最近沉迷于AC不能自拔,每天寝室.机房两点一线.由于长时间坐在电脑边,缺乏运动.他决定充分利用每次从寝室到机房的时间,在校园里散散步.整个HDU校 ...
- hdu 1142(迪杰斯特拉+记忆化搜索)
A Walk Through the Forest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- hdu 4052 线段树扫描线、奇特处理
Adding New Machine Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
随机推荐
- Zimbra无需登录RCE漏洞利用
2019年3月13号,一名国外的安全研究员在他的博客上公布了zimbra RCE漏洞相关信息,但其中并未提到一些漏洞利用细节. 经过一段时间努力,根据网上各位大牛的分析和我自己的理解,在此我将整个漏洞 ...
- C# __arglist 关键字
using System.Runtime.InteropServices; namespace Alpha { class Beta { [DllImport("msvcrt.dll&quo ...
- python 简单搭建非阻塞式单进程,select模式,epoll模式服务
由于经常被抓取文章内容,在此附上博客文章网址:,偶尔会更新某些出错的数据或文字,建议到我博客地址 : --> 点击这里 可以看我的上篇文章 <python 简单搭建阻塞式单进程,多进程, ...
- python os.path 的使用
import os #该文件所在位置:D:\第1层\第2层\第3层\第4层\第5层\test11.py path1 = os.path.dirname(__file__) print(path1)#获 ...
- FunDA(6)- Reactive Streams:Play with Iteratees、Enumerator and Enumeratees
在上一节我们介绍了Iteratee.它的功能是消耗从一些数据源推送过来的数据元素,不同的数据消耗方式代表了不同功能的Iteratee.所谓的数据源就是我们这节要讨论的Enumerator.Enumer ...
- 【wireshark】插件开发(二):Lua插件开发介绍
1. Wireshark对Lua的支持 本节相关内容可参考Wireshark开发指南第10章”Lua Support in Wireshark”. Wireshark集成了Lua解释器,以支持Lua脚 ...
- .Net - WebApi
WebApi C#进阶系列 - WebApi: WebApi 服务监控 + log4net:
- 剑指offer五十之数组中重复的数字
一.题目 在一个长度为n的数组里的所有数字都在0到n-1的范围内. 数组中某些数字是重复的,但不知道有几个数字是重复的.也不知道每个数字重复几次.请找出数组中任意一个重复的数字. 例如,如果输入长度为 ...
- Java之集合(二十一)LinkedTransferQueue
转载请注明源出处:http://www.cnblogs.com/lighten/p/7505355.html 1.前言 本章介绍无界的阻塞队列LinkedTransferQueue,JDK7才提供了这 ...
- java 中break 和continue 的非常规用法
正常情况下,break只能断掉最近的循环.(比如二个嵌套的for循环中 ,第二个循环的break.不会中断第一个for循环) 问题是: 嵌套中 如果要断掉任意其中的循环怎么做? 答案是: 加一个lab ...