搜索专题: HDU1428漫步校园
漫步校园
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4459 Accepted Submission(s): 1401
3
1 2 3
1 2 3
1 2 3
3
1 1 1
1 1 1
1 1 1
1
6
RunId : 21258881 Language : G++ Author : hnustwanghe
Code Render Status : Rendered By HDOJ G++ Code Render Version 0.01 Beta
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
using namespace std;
const int N = 50 + 5;
const int INF = (1<<30);
long long Min[N][N],dp[N][N];
typedef struct node{
int x,y,val;
node(int x=0,int y=0,int val=0):x(x),y(y),val(val){}
}Node;
const int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
int mat[N][N];
int n,newx,newy;
long long DFS(int x,int y){
if(x == n-1 && y == n-1) return 1;
if(dp[x][y]>0) return dp[x][y];
for(int d=0;d<4;d++){
newx = x + dir[d][0];
newy = y + dir[d][1];
if(newx >= 0 && newx < n && newy >= 0 && newy < n && Min[x][y] > Min[newx][newy]){
dp[x][y] += DFS(newx,newy);
}
}
return dp[x][y];
}
void Init(int n){
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
Min[i][j] = INF;
memset(dp,0,sizeof(dp));
}
void BFS(){
queue <Node> Q;
Node t,s;
Min[n-1][n-1] = mat[n-1][n-1];
t.x = n-1,t.y = n-1,t.val = mat[n-1][n-1];
Q.push(t);
while(!Q.empty()){
t = Q.front();Q.pop();
for(int d=0;d<4;d++){
newx = t.x + dir[d][0];
newy = t.y + dir[d][1];
if(newx >=0 && newx < n && newy >= 0 && newy < n){
s.val = t.val + mat[newx][newy];
if(s.val < Min[newx][newy]){
s.x = newx , s.y = newy;
Min[newx][newy] = s.val;
Q.push(s);
}
}
}
}
}
int main(){
while(scanf("%d",&n)==1){
Init(n);
for(int i=0;i<n;i++)
for(int j=0;j<n;j++){
scanf("%d",&mat[i][j]);
}
BFS();
printf("%I64d\n",DFS(0,0));
}
}
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
using namespace std;
const int N = 50 + 5;
const int INF = (1<<30);
long long Min[N][N],dp[N][N];
typedef struct node{
int x,y,val;
node(int x=0,int y=0,int val=0):x(x),y(y),val(val){}
}Node;
const int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
int mat[N][N];
int n,newx,newy; long long DFS(int x,int y){
if(x == n-1 && y == n-1) return 1;
if(dp[x][y]>0) return dp[x][y];
for(int d=0;d<4;d++){
newx = x + dir[d][0];
newy = y + dir[d][1];
if(newx >= 0 && newx < n && newy >= 0 && newy < n && Min[x][y] > Min[newx][newy]){
dp[x][y] += DFS(newx,newy);
}
}
return dp[x][y];
}
void Init(int n){
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
Min[i][j] = INF;
memset(dp,0,sizeof(dp));
} void BFS(){
queue <Node> Q;
Node t,s;
Min[n-1][n-1] = mat[n-1][n-1];
t.x = n-1,t.y = n-1,t.val = mat[n-1][n-1];
Q.push(t);
while(!Q.empty()){
t = Q.front();Q.pop();
for(int d=0;d<4;d++){
newx = t.x + dir[d][0];
newy = t.y + dir[d][1];
if(newx >=0 && newx < n && newy >= 0 && newy < n){
s.val = t.val + mat[newx][newy];
if(s.val < Min[newx][newy]){
s.x = newx , s.y = newy;
Min[newx][newy] = s.val;
Q.push(s);
}
}
}
}
} int main(){
while(scanf("%d",&n)==1){
Init(n);
for(int i=0;i<n;i++)
for(int j=0;j<n;j++){
scanf("%d",&mat[i][j]);
}
BFS();
printf("%I64d\n",DFS(0,0));
}
}
搜索专题: HDU1428漫步校园的更多相关文章
- hdu1428漫步校园( 最短路+BFS(优先队列)+记忆化搜索(DFS))
Problem Description LL最近沉迷于AC不能自拔,每天寝室.机房两点一线.由于长时间坐在电脑边,缺乏运动.他决定充分利用每次从寝室到机房的时间,在校园里散散步.整个HDU校园呈方形布 ...
- hdu1428漫步校园
#include <queue> #include <iostream> #include <algorithm> #include <cstring> ...
- 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校 ...
- HDOJ 1428 漫步校园
漫步校园 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU(搜索专题) 1000 N皇后问题(深度优先搜索DFS)解题报告
前几天一直在忙一些事情,所以一直没来得及开始这个搜索专题的训练,今天做了下这个专题的第一题,皇后问题在我没有开始接受Axie的算法低强度训练前,就早有耳闻了,但一直不知道是什么类型的题目,今天一看,原 ...
- NOIP2018提高组金牌训练营——搜索专题
NOIP2018提高组金牌训练营——搜索专题 1416 两点 福克斯在玩一款手机解迷游戏,这个游戏叫做”两点”.基础级别的时候是在一个n×m单元上玩的.像这样: 每一个单元有包含一个有色点.我们将用不 ...
随机推荐
- java.lang.IllegalArgumentException: java.io.IOException: Alias name [tomcat] does not identify a key entry
java.lang.IllegalArgumentException: java.io.IOException: Alias name [tomcat] does not identify a key ...
- Static使用
1.什么是static? static 是C++中很常用的修饰符,它被用来控制变量的存储方式和可见性. 其余控制变量存储方式的关键字为auto.register.extern. 2.为什么要引入sta ...
- k8s安装报错 Error: unknown flag: --experimental-upload-certs
今天安装k8sV1.16的版本时候,执行突然发现命令不对,之前安装V1.15的时候是可以的,可能是版本升级的原因. 解决: unknown flag: --experimental-upload-ce ...
- You Only Look Once Unified, Real-Time Object Detection(你只需要看一次统一的,实时的目标检测)
我们提出了一种新的目标检测方法YOLO.先前的目标检测工作重新利用分类器来执行检测.相反,我们将目标检测作为一个回归问题来处理空间分离的边界框和相关的类概率.单个神经网络在一次评估中直接从完整图像预测 ...
- mac 的 ping 命令怎么停掉?
Widnows下的Ping不会只Ping4次,mac 会不停的Ping下去,需要停止,按下键盘上的 control+c 键即可停掉 Ping 过程.
- (74)c++再回顾一继承和派生
一:继承和派生 0.默认构造函数即不带参数的构造函数或者是系统自动生成的构造函数.每一个类的构造函数可以有多个,但是析构函数只能有一个. 1.采用公用public继承方式,则基类的公有成员变量和成员函 ...
- Spring Cloud Stream教程(二)主要概念
Spring Cloud Stream提供了一些简化了消息驱动的微服务应用程序编写的抽象和原语.本节概述了以下内容: Spring Cloud Stream的应用模型 Binder抽象 持续的发布 - ...
- jQuery file upload callback options
autoUpload By default, files added to the widget are uploaded as soon as the user clicks on the star ...
- OperationCenter Docker运行环境及其依赖启动脚本
1.Portainer docker rm -f portainer docker run -d -p : --name portainer --restart always portainer/po ...
- 破解Excel 工作表/薄密码
新建excel 在右上角的ThisWorkbook右键插入模块复制下列CODE. Option Explicit Public Sub AllInternalPasswords()' Breaks w ...