【Link】:

【Description】



在一个r*c的格子上;

求最长的下降路径;

【Solution】



记忆化搜索;

f[x][y]表示从(x,y)这个格子往下还能走多远;

因为是严格递增,所以有单调性.



【NumberOf WA】



0



【Reviw】

【Code】


#include <bits/stdc++.h>
using namespace std; const int N = 100+10;
const int dx[5] = {0,1,-1,0,0};
const int dy[5] = {0,0,0,1,-1};
const int INF = 0x3f3f3f3f; int T,r,c,a[N][N],f[N][N];
char s[30]; int dfs(int x,int y){
if (f[x][y]!=-1) return f[x][y];
int ma = 0;
for (int i = 1;i <= 4;i++){
int tx = x + dx[i],ty = y + dy[i];
if (tx <1 || tx > r || ty <1 || ty > c) continue;
if (a[tx][ty]<a[x][y])
ma = max(ma,dfs(tx,ty));
}
return f[x][y] = ma+1;
} int main(){
//freopen("F:\\rush.txt","r",stdin);
scanf("%d",&T);
while (T--){
scanf("%s",s+1);
scanf("%d%d",&r,&c);
for (int i = 1;i <= r;i++)
for (int j = 1;j <= c;j++)
scanf("%d",&a[i][j]);
memset(f,255,sizeof f);
int t = dfs(1,1);
for (int i = 1;i <= r;i++)
for (int j = 1;j <= c;j++)
t = max(t,dfs(i,j));
printf("%s: %d\n",s+1,t);
}
return 0;
}

【Uva 10285】Longest Run on a Snowboard的更多相关文章

  1. 【UVA】10285-Longest Run on a Snowboard(动态规划)

    这是一个简单的问题.你并不需要打印路径. 状态方程dp[i][j] = max(dp[i-1][j],dp[i][j-1],dp[i+1][j],dp[i][j+1]); 14003395 10285 ...

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

    Longest Run on a Snowboard Input: standard input Output: standard output Time Limit: 5 seconds Memor ...

  3. UVA 10285 Longest Run on a Snowboard(记忆化搜索)

    Problem C Longest Run on a Snowboard Input: standard input Output: standard output Time Limit: 5 sec ...

  4. 【BZOJ1844/2210】Pku1379 Run Away 模拟退火

    [BZOJ1844/2210]Pku1379 Run Away 题意:矩形区域中有一堆点,求矩形中一个位置使得它到所有点的距离的最小值最大. 题解:模拟退火的裸题,再调调调调调参就行了~ #inclu ...

  5. [动态规划]UVA10285 - Longest Run on a Snowboard

    Problem C Longest Run on a Snowboard Input: standard input Output: standard output Time Limit: 5 sec ...

  6. 【巧妙算法系列】【Uva 11464】 - Even Parity 偶数矩阵

    偶数矩阵(Even Parity, UVa 11464) 给你一个n×n的01矩阵(每个元素非0即1),你的任务是把尽量少的0变成1,使得每个元素的上.下.左.右的元素(如果存在的话)之和均为偶数.比 ...

  7. 【贪心+中位数】【UVa 11300】 分金币

    (解方程建模+中位数求最短累积位移) 分金币(Spreading the Wealth, UVa 11300) 圆桌旁坐着n个人,每人有一定数量的金币,金币总数能被n整除.每个人可以给他左右相邻的人一 ...

  8. 【UVa 10881】Piotr's Ants

    Piotr's Ants Porsition:Uva 10881 白书P9 中文改编题:[T^T][FJUT]第二届新生赛真S题地震了 "One thing is for certain: ...

  9. 【UVa 116】Unidirectional TSP

    [Link]:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

随机推荐

  1. Codeforces Round #249 (Div. 2) (模拟)

    C. Cardiogram time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. Linux平台不同解压缩命令的使用方法

    作者:郭孝星 微博:郭孝星的新浪微博 邮箱:allenwells@163.com 博客:http://blog.csdn.net/allenwells github:https://github.co ...

  3. SurfaceView左右滑动切换黑屏问题解决方式

    在项目中使用的是高德地图,放置MapView的Fragment和其它Fragment放置一个ViewPager中切换:当从MapView的Fragment切换到其它Fragment或者从其它Fragm ...

  4. 小贝_redis list类型学习

    redis  list类型 一.查看list类型的命令 二.list命令具体解释 一.查看list类型的命令 1.在终端数据 help @list 127.0.0.1:6379>help @li ...

  5. emmet教程

    https://www.zfanw.com/blog/zencoding-vim-tutorial-chinese.html https://www.zfanw.com/blog/zencoding- ...

  6. tomcat:Could not publish to the server. java.lang.IndexOutOfBoundsException

    1.将工程加入到tomcat,报上述错误 2. run--maven build 报jar包错误: invalid LOC header (bad signature) 3.根据提示找到上述jar包, ...

  7. sql排名函数--四个

    1 row_number 2 rank 3 dense_rank 4 ntile 例子如下: select * into #MyTablefrom(select '语文' as 课程,70 as 成绩 ...

  8. 5、Go if else 条件判断

    package main import "fmt" func main(){ //注:在Go里面没有三元表达式”?:”,所以你只能使用条件判断语句. //示例一 if 7%2==0 ...

  9. Ubuntu 18.04图形化软件包管理器

    1.ubuntu软件这个管理工具提供了一种管理您系统中软件的好方法,通过他可以很直观的查找软件安装很简单,打开终端,输入以下命令:----------------------------------- ...

  10. HDU-1035 Robot Motion 模拟问题(水题)

    题目链接:https://cn.vjudge.net/problem/HDU-1035 水题 代码 #include <cstdio> #include <map> int h ...