hdu1078 bfs
- //Accepted 468 KB 812 ms
- //bfs+dp
- #include <cstdio>
- #include <cstring>
- #include <iostream>
- using namespace std;
- #include <queue>
- ;
- int map[imax_n][imax_n];
- int dp[imax_n][imax_n];
- bool vis[imax_n][imax_n];
- ]={,,-,,,,,-};
- int n;
- int k;
- queue<int > qx;
- queue<int > qy;
- int max(int a,int b)
- {
- return a>b?a:b;
- }
- void bfs()
- {
- memset(dp,,sizeof(dp));
- memset(vis,,sizeof(vis));
- while (!qx.empty()) qx.pop();
- while (!qy.empty()) qy.pop();
- qx.push();
- qy.push();
- dp[][]=map[][];
- vis[][]=true;
- while (!qx.empty())
- {
- int x=qx.front();
- qx.pop();
- int y=qy.front();
- qy.pop();
- vis[x][y]=false;
- int nx,ny;
- ;j<;j++)
- ;i<=k;i++)
- {
- nx=x+i*d[j][];
- ny=y+i*d[j][];
- && nx<n && ny>= && ny<n && map[nx][ny]>map[x][y])
- {
- if (dp[nx][ny]<dp[x][y]+map[nx][ny])
- {
- dp[nx][ny]=dp[x][y]+map[nx][ny];
- if (!vis[nx][ny])
- {
- vis[nx][ny]=true;
- qx.push(nx);
- qy.push(ny);
- }
- }
- }
- }
- }
- ;
- ;i<n;i++)
- ;j<n;j++)
- ans=max(ans,dp[i][j]);
- printf("%d\n",ans);
- }
- int main()
- {
- && k==-))
- {
- ;i<n;i++)
- ;j<n;j++)
- scanf("%d",&map[i][j]);
- bfs();
- }
- ;
- }
hdu1078 bfs的更多相关文章
- 图的遍历(搜索)算法(深度优先算法DFS和广度优先算法BFS)
图的遍历的定义: 从图的某个顶点出发访问遍图中所有顶点,且每个顶点仅被访问一次.(连通图与非连通图) 深度优先遍历(DFS): 1.访问指定的起始顶点: 2.若当前访问的顶点的邻接顶点有未被访问的,则 ...
- 【BZOJ-1656】The Grove 树木 BFS + 射线法
1656: [Usaco2006 Jan] The Grove 树木 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 186 Solved: 118[Su ...
- POJ 3278 Catch That Cow(bfs)
传送门 Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 80273 Accepted: 25 ...
- POJ 2251 Dungeon Master(3D迷宫 bfs)
传送门 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28416 Accepted: 11 ...
- Sicily 1215: 脱离地牢(BFS)
这道题按照题意直接BFS即可,主要要注意题意中的相遇是指两种情况:一种是同时到达同一格子,另一种是在移动时相遇,如Paris在(1,2),而Helen在(1,2),若下一步Paris到达(1,1),而 ...
- Sicily 1048: Inverso(BFS)
题意是给出一个3*3的黑白网格,每点击其中一格就会使某些格子的颜色发生转变,求达到目标状态网格的操作.可用BFS搜索解答,用vector储存每次的操作 #include<bits/stdc++. ...
- Sicily 1444: Prime Path(BFS)
题意为给出两个四位素数A.B,每次只能对A的某一位数字进行修改,使它成为另一个四位的素数,问最少经过多少操作,能使A变到B.可以直接进行BFS搜索 #include<bits/stdc++.h& ...
- Sicily 1051: 魔板(BFS+排重)
相对1150题来说,这道题的N可能超过10,所以需要进行排重,即相同状态的魔板不要重复压倒队列里,这里我用map储存操作过的状态,也可以用康托编码来储存状态,这样时间缩短为0.03秒.关于康托展开可以 ...
- Sicily 1150: 简单魔板(BFS)
此题可以使用BFS进行解答,使用8位的十进制数来储存魔板的状态,用BFS进行搜索即可 #include <bits/stdc++.h> using namespace std; int o ...
随机推荐
- Technical notes fornight
1.8.2016 Royal trumpeters heralded the beginning of the annual ceremony, as Norway's royal family an ...
- Link Collecting
----------------------------------\ ACM入门总结之常见输入输出格式暨hdu1089~1096 题解,谨献给对acm感兴趣的新人 - 博客频道 - CSDN.NET ...
- Java虚拟机类加载机制——案例分析
转载: Java虚拟机类加载机制--案例分析 在<Java虚拟机类加载机制>一文中详细阐述了类加载的过程,并举了几个例子进行了简要分析,在文章的最后留了一个悬念给各位,这里来揭开这个悬 ...
- canvas实现钟表
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Spring 框架整理
在web.xml中配置以下内容 <!-- 配置Spring MVC DispatcherServlet --> <servlet> <servlet-name>MV ...
- PHP Warning: ob_start() : output handler 'ob_gzhandler conflicts with 'zlib output compression'
安装phpcms过程中,会遇到Warning: ob_start() : output handler 'ob_gzhandler conflicts with 'zlib output compr ...
- hdu----(3068)最长回文(manacher)
最长回文 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- 127. 126. Word Ladder *HARD* -- 单词每次变一个字母转换成另一个单词
127. Given two words (beginWord and endWord), and a dictionary's word list, find the length of short ...
- journal
dec 5 rpt prep exam dec 4 lie to me dec 3 exam dec 2 preparation for exam dec 1 preparation for exam ...
- centos chkconfig 服务设置
chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息.谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接. 使用语法:chkconfig [--ad ...