题目大意:

从(1,1)到(n,n),每经过一个点都要花费一定的时间,问花最短时间的路径有多少条

dfs+dp

先用bfs把所有到n花费的时间逆向dp计算一遍

再用dfs不断找到前一个对应的较短路径的点不断搜索路径

 #include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
#define LL long long
#define N 52 struct node{
int x,y;
}; queue<node> q;
int dir[][]={{,},{,-},{,},{-,}},dp[N][N],mat[N][N],n;
LL s[N][N]; void bfs()
{
dp[n][n]=mat[n][n];
node a;
a.x=n,a.y=n;
q.push(a);
while(!q.empty()){
node b=q.front();
q.pop();
for(int i=;i<;i++){
int xx=b.x+dir[i][];
int yy=b.y+dir[i][];
if(xx>=&&xx<=n&&yy>=&&yy<=n){
if(dp[xx][yy]==||dp[xx][yy]>dp[b.x][b.y]+mat[xx][yy]){
node c;
c.x=xx,c.y=yy;
q.push(c);
dp[xx][yy]=dp[b.x][b.y]+mat[xx][yy];
}
}
}
}
} LL dfs(int x,int y)
{ if(x==n&&y==n) return ;
if(s[x][y]) return s[x][y];//在记忆化搜索中,就是利用已知的数据直接代入,
//避免重复计算,在此就是把数据保存在s中
for(int i=;i<;i++){
int xx=x+dir[i][];
int yy=y+dir[i][];
if(xx>=&&xx<=n&&yy>=&&yy<=n){
if(dp[xx][yy]<dp[x][y]){
s[x][y]+=dfs(xx,yy);
}
}
}
return s[x][y];
} int main()
{
while(~scanf("%d",&n)){ memset(dp,,sizeof(dp));
memset(s,,sizeof(s)); for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
scanf("%d",&mat[i][j]);
}
} bfs(); /*for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
printf("%d ",dp[i][j]);
}
puts("");
}*/
printf("%I64d\n",dfs(,));
}
return ;
}

HDU 1278的更多相关文章

  1. hdu 1278 逃离迷宫

    逃离迷宫 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  2. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  3. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  4. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  5. 51Nod 1278 相离的圆

    51Nod 1278 相离的圆 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1278 1278 相离的圆 基 ...

  6. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  7. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  8. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  9. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

随机推荐

  1. Codeforces GYM 100741A . Queries

    time limit per test 0.25 seconds memory limit per test 64 megabytes input standard input output stan ...

  2. learnpythonthehardway EX41 相关

    str.count() # str.count()方法用于统计字符串里某个字符出现的次数.可选参数为在字符串搜索的开始与结束位置. # str.count(sub, start= 0,end=len( ...

  3. 如何使用capedit分割数据包文件

    wireshark是一个网络数据包的分析工具,主要用来捕获网卡上的数据包并显示数据包的详细内容.在处理一些大的数据包文件时,如果直接用wireshark图形工具打开一些大文件的数据包会出现响应慢甚至没 ...

  4. 第二周作业xml学习情况

    1.xml简介 可扩展标记语言是一种很像超文本标记语言的标记语言. 它的设计宗旨是传输数据,而不是显示数据. 它的标签没有被预定义.您需要自行定义标签. 它被设计为具有自我描述性. 它是W3C的推荐标 ...

  5. ubuntu 安装 pcap

    最近在做负载均衡配置,希望将多个dhcp服务配置成一个虚拟dhcp地址,实现dhcp服务高可用.然而配置完成后却发现一个问题,该如何测试呢. 因此就要用上python了,然后ubuntu下面用pip ...

  6. Using URL Schemes to Communicate with Apps

    要素:1)通信双方:2)协议:3)支持机制(系统,进行协议注册):4)数据 https://developer.apple.com/library/content/documentation/iPho ...

  7. 众皓网络(T 面试)

    1.你们项目中哪里用到了Redis? 2.Redis中存储的数据,你们什么时候进行更新? 3.你用过消息队列吗? 4.你写的这个微服务项目拆分成了几个服务? 5.SpringCloud项目怎么部署的?

  8. Js 之获取QueryString的几种方法

    一.正则匹配 function getQueryString(name) { var reg = new RegExp('(^|&)' + name + '=([^&]*)(& ...

  9. es 集群部署

    下载 [root@localhost ~]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.1 ...

  10. python之str (字符型)

    用途: 存储少量的数据,+ *int 切片, 其他操作方法 切片还是对其进行任何操作,获取的内容全部是strl类型 存储数据单一 格式: 在python中用引号引起来的就是字符串 '今天吃了没?' 1 ...