【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. 2015-8-29阿里校园招聘研发project师笔试题

    前言:原题来自于网络:http://www.cnblogs.com/nausicaa/p/3946694.html.本人依据自己理解对题目进行解答.因为水平有限.题目有不会做.做错的地方.欢迎大家留言 ...

  2. 汇编中中括号[]作用以及lea和mov指令的区别

    现在总结一下:其中牵扯到lea指令,mov指令,[] 一.lea指令:对于寄存器来说:第二个操作数是寄存器必须要加[],不然报错,这里lea就是取[寄存器]的值,如:mov eax,2lea ebx, ...

  3. angularjs 路由 ngRoute tab切换

    <!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...

  4. c++命名规范与代码风格

    http://blog.sina.com.cn/s/blog_a3a8d0b1010100uw.html http://www.cnblogs.com/len3d/archive/2008/02/01 ...

  5. hdu_5154 拓扑

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #i ...

  6. POJ 2478 线性递推欧拉函数

    题意: 求sigma phi(n) 思路: 线性递推欧拉函数 (维护前缀和) //By SiriusRen #include <cstdio> using namespace std; # ...

  7. HBase框架基础(二)

    * HBase框架基础(二) 上一节我们了解了HBase的架构原理和模块组成,这一节我们先来聊一聊HBase的读写数据的过程. * HBase的读写流程及3个机制 HBase的读数据流程: 1.HRe ...

  8. 相机拍照友盟检测crash是为什么?

    友盟报错如下* setObjectForKey: object cannot be nil (key: UIImagePickerControllerOriginalImage)(null)(( 0 ...

  9. UI Framework-1: Aura Focus and Activation

    Focus and Activation Focus and Activation are closely related.   Definitions Focused window - this i ...

  10. JAVA版本区块链钱包核心代码

    Block.java package com.ppblock.blockchain.core; import java.io.Serializable; /** * 区块 * @author yang ...