1. //Accepted 468 KB 812 ms
  2. //bfs+dp
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <iostream>
  6. using namespace std;
  7. #include <queue>
  8. ;
  9. int map[imax_n][imax_n];
  10. int dp[imax_n][imax_n];
  11. bool vis[imax_n][imax_n];
  12. ]={,,-,,,,,-};
  13. int n;
  14. int k;
  15. queue<int > qx;
  16. queue<int > qy;
  17. int max(int a,int b)
  18. {
  19. return a>b?a:b;
  20. }
  21. void bfs()
  22. {
  23. memset(dp,,sizeof(dp));
  24. memset(vis,,sizeof(vis));
  25. while (!qx.empty()) qx.pop();
  26. while (!qy.empty()) qy.pop();
  27. qx.push();
  28. qy.push();
  29. dp[][]=map[][];
  30. vis[][]=true;
  31. while (!qx.empty())
  32. {
  33. int x=qx.front();
  34. qx.pop();
  35. int y=qy.front();
  36. qy.pop();
  37. vis[x][y]=false;
  38. int nx,ny;
  39. ;j<;j++)
  40. ;i<=k;i++)
  41. {
  42. nx=x+i*d[j][];
  43. ny=y+i*d[j][];
  44. && nx<n && ny>= && ny<n && map[nx][ny]>map[x][y])
  45. {
  46. if (dp[nx][ny]<dp[x][y]+map[nx][ny])
  47. {
  48. dp[nx][ny]=dp[x][y]+map[nx][ny];
  49. if (!vis[nx][ny])
  50. {
  51. vis[nx][ny]=true;
  52. qx.push(nx);
  53. qy.push(ny);
  54. }
  55. }
  56. }
  57. }
  58. }
  59. ;
  60. ;i<n;i++)
  61. ;j<n;j++)
  62. ans=max(ans,dp[i][j]);
  63. printf("%d\n",ans);
  64. }
  65. int main()
  66. {
  67. && k==-))
  68. {
  69. ;i<n;i++)
  70. ;j<n;j++)
  71. scanf("%d",&map[i][j]);
  72. bfs();
  73. }
  74. ;
  75. }

hdu1078 bfs的更多相关文章

  1. 图的遍历(搜索)算法(深度优先算法DFS和广度优先算法BFS)

    图的遍历的定义: 从图的某个顶点出发访问遍图中所有顶点,且每个顶点仅被访问一次.(连通图与非连通图) 深度优先遍历(DFS): 1.访问指定的起始顶点: 2.若当前访问的顶点的邻接顶点有未被访问的,则 ...

  2. 【BZOJ-1656】The Grove 树木 BFS + 射线法

    1656: [Usaco2006 Jan] The Grove 树木 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 186  Solved: 118[Su ...

  3. POJ 3278 Catch That Cow(bfs)

    传送门 Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 80273   Accepted: 25 ...

  4. POJ 2251 Dungeon Master(3D迷宫 bfs)

    传送门 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28416   Accepted: 11 ...

  5. Sicily 1215: 脱离地牢(BFS)

    这道题按照题意直接BFS即可,主要要注意题意中的相遇是指两种情况:一种是同时到达同一格子,另一种是在移动时相遇,如Paris在(1,2),而Helen在(1,2),若下一步Paris到达(1,1),而 ...

  6. Sicily 1048: Inverso(BFS)

    题意是给出一个3*3的黑白网格,每点击其中一格就会使某些格子的颜色发生转变,求达到目标状态网格的操作.可用BFS搜索解答,用vector储存每次的操作 #include<bits/stdc++. ...

  7. Sicily 1444: Prime Path(BFS)

    题意为给出两个四位素数A.B,每次只能对A的某一位数字进行修改,使它成为另一个四位的素数,问最少经过多少操作,能使A变到B.可以直接进行BFS搜索 #include<bits/stdc++.h& ...

  8. Sicily 1051: 魔板(BFS+排重)

    相对1150题来说,这道题的N可能超过10,所以需要进行排重,即相同状态的魔板不要重复压倒队列里,这里我用map储存操作过的状态,也可以用康托编码来储存状态,这样时间缩短为0.03秒.关于康托展开可以 ...

  9. Sicily 1150: 简单魔板(BFS)

    此题可以使用BFS进行解答,使用8位的十进制数来储存魔板的状态,用BFS进行搜索即可 #include <bits/stdc++.h> using namespace std; int o ...

随机推荐

  1. Technical notes fornight

    1.8.2016 Royal trumpeters heralded the beginning of the annual ceremony, as Norway's royal family an ...

  2. Link Collecting

    ----------------------------------\ ACM入门总结之常见输入输出格式暨hdu1089~1096 题解,谨献给对acm感兴趣的新人 - 博客频道 - CSDN.NET ...

  3. Java虚拟机类加载机制——案例分析

    转载: Java虚拟机类加载机制--案例分析   在<Java虚拟机类加载机制>一文中详细阐述了类加载的过程,并举了几个例子进行了简要分析,在文章的最后留了一个悬念给各位,这里来揭开这个悬 ...

  4. canvas实现钟表

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. Spring 框架整理

    在web.xml中配置以下内容 <!-- 配置Spring MVC DispatcherServlet --> <servlet> <servlet-name>MV ...

  6. 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 ...

  7. hdu----(3068)最长回文(manacher)

    最长回文 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  8. 127. 126. Word Ladder *HARD* -- 单词每次变一个字母转换成另一个单词

    127. Given two words (beginWord and endWord), and a dictionary's word list, find the length of short ...

  9. journal

    dec 5 rpt prep exam dec 4 lie to me dec 3 exam dec 2 preparation for exam dec 1 preparation for exam ...

  10. centos chkconfig 服务设置

    chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息.谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接. 使用语法:chkconfig [--ad ...