记忆化搜索模板题.

仔细想想搜索时会重复的地方, 然后把重复的地方记下来就好啦!

 1 #include <cstdio>
 2 #include <algorithm>
 3 #include <iostream>
 4 #include <cstring>
 5 using namespace std;
 6 const int MAXC = 100 + 10;
 7 const int INF = 0x3f3f3f3f;
 8
 9 inline int read()
10 {
11     int x = 0; char ch = getchar();
12     while(!isdigit(ch)) ch = getchar();
13     while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
14     return x;
15 }
16
17 int M[MAXC][MAXC], d[MAXC][MAXC], dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
18 int R, C;
19
20 int dfs(int x, int y)
21 {
22     if(d[x][y] != -1) return d[x][y];
23
24     d[x][y] = 0;
25     for(int i = 0; i < 4; i++)
26         if(M[x + dx[i]][y + dy[i]] < M[x][y])
27             d[x][y] = max(dfs(x + dx[i], y + dy[i]), d[x][y]);
28
29     return ++d[x][y];
30 }
31
32 int main()
33 {
34     //freopen("10285.in", "r", stdin);
35     int N;
36     cin>>N;
37
38     string s;
39
40     while(N--)
41     {
42         cin>>s;
43         R = read(), C = read();
44
45         memset(M, 0, sizeof(M));
46         memset(d, -1, sizeof(d));
47         for(int i = 1; i <= R; i++)
48             for(int j = 1; j <= C; j++)
49                 M[i][j] = read();
50
51         for(int i = 1; i <= R; i++)
52             {for(int j = 1; j <= C; j++)
53                 cout<<M[i][j]<<" ";
54             cout<<endl;}
55
56         int ans = -INF;
57         for(int i = 1; i <= R; i++)
58             for(int j = 1; j <= C; j++)
59                 ans = max(dfs(i, j), ans);
60
61         cout<<s<<": "<<--ans<<endl;
62     }
63     return 0;
64 }

做水题真好玩!

转载于:https://www.cnblogs.com/wsmrxc/p/9024891.html

Uva10285 Longest Run on a Snowboard相关推荐

  1. UVA10285 Longest Run on a Snowboard【DFS+记忆化搜索】

    Michael likes snowboarding. That's not very surprising, since snowboarding is really great. The bad ...

  2. UVA-10285 Longest Run on a Snowboard (递推)

    题目大意:滑雪.给一个二维数组,找出最长的连续下降序列的长度. 题目分析:定义dp(i,j)表示以a[i][j]结尾的最长连续下降序列的长度,则dp(i,j)=max(dp(i-1,j),dp(i+1 ...

  3. uva 10285 - Longest Run on a Snowboard(dp+记忆化搜索)

    1.http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  4. 10285 - Longest Run on a Snowboard

    描述:寻找一个数,从这个数上.下.左.右四个方向寻找一堆数,使之为递增或者递减数列,输出这个数列的个数 #include <cstdio> #include <cstring> ...

  5. uva 10285——Longest Run on a Snowboard

    题意:在一个R*c的矩阵上找一条高度严格递减的最长路,起点任意,每次可以走上下左右. 思路:DAG上的最长路问题,直接套用记忆化搜索的模板,dp(i,j)=max(dp(ii,jj)四个方向最大值), ...

  6. π-Algorithmist分类题目(3)

    原题网站:Algorithmist,http://www.algorithmist.com/index.php/Main_Page π-Algorithmist分类题目(3) Probability ...

  7. 紫书《算法竞赛入门经典》

    紫书<算法竞赛入门经典>题目一览 第3章 数组和字符串(例题) UVA 272 TEX Quotes UVA 10082 WERTYU UVA 401 Palindromes UVA 34 ...

  8. UVa Online Judge 工具網站

    UVa Online Judge 工具網站 转自http://www.csie.ntnu.edu.tw/~u91029/uva.html Lucky貓的ACM園地,Lucky貓的 ACM 中譯題目 M ...

  9. 提取了下刘汝佳推荐的题号...

    今天闲来没事上uva oj提取了下刘汝佳推荐的acm题号,原始数据如下: Volume 0. Getting Started    10055 - Hashmat the Brave Warrior ...

最新文章

  1. java三段式if_Java几种常用的断言风格你怎么选?
  2. 【iOS官方文档翻译】iOS的蓝牙连接、数据接收及发送
  3. php ci项目总结,分享关于php CI框架使用的一点小总结
  4. 画原理图和PCB图该注意什么?
  5. hive 时间转字符串_07697.0.3如何在Kerberos环境下用Ranger完成对Hive的行过滤及列脱敏...
  6. 计算机usb接口充电效率差,usb2.0和3.0的区别 从传输速度和充电效率等来区别
  7. android版记账本
  8. 基本的maven的命令行命令
  9. VTK:轮廓 Glow Pass用法实战
  10. 解决Based on configured schedule, the given trigger ‘triggerGroupName_FREEZE_JOB.triggerName_FREEZE...
  11. 资深面试官解答:大厂月薪过20K的测试工程师,都需要满足哪些要求?
  12. grasshopper python_【转】精华教学 | GH_Cpython——将原生的 Python 与机器学习框架引入Grasshopper...
  13. 破解安装IAR编辑器
  14. java段子_Java程序员的内涵段子
  15. 批量下载bilibili视频
  16. SAP会计借贷(转载)
  17. 时间流逝,岁月里所有的狼狈
  18. word文件点击打印没反应
  19. java面向对象知识点整理--用前人智慧,为后人铺路
  20. Stream流获取(集合,数组)

热门文章

  1. dm7和mysql_【干货分享】达梦数据库DM7的新特性发布啦
  2. 规模 300+ 的研发团队,怎样保持工程高质高效?
  3. C# winform 编写记事本
  4. Linux下Apache虚拟主机配置
  5. Hibernate 异常 Unable to instantiate default tuplizer
  6. OGRE例子:Demo_Ocean 源码解析
  7. EFI Shell 命令参考
  8. 出问题 初始化ucosiii_STM32 ucosii 双堆栈初始化问题
  9. window连接不上linux ftp_Linux文件自动备份方案
  10. Win10系统下安装VC6.0教程