【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. nyoj914(二分搜索+贪心)

    题目意思: pid=914">acm.nyist.net/JudgeOnline/problem.php?pid=914 如今有n个物品的重量和价值各自是Wi和Vi,你能帮他从中选出k ...

  2. xcode5. 安装cocos2d-x 学习中。。。

    找了一些帖子  没搞出来,后来找到原因了   如今的cocos2d版本号在xcode.5上 没右模版了. 用命令行 来运行.看了官方的文档.最终攻克了--- 对于自己解决的问题都会感到点兴奋. .. ...

  3. vim 插件之supertab

    supertab.vim 这个插件是用来把tab键作为只能补全的映射,当然,具体更能肯定不仅仅只是如此,等待以后发现吧 地址 http://github.com/ervandew/supertab h ...

  4. bzoj1010: [HNOI2008]玩具装箱toy(DP+斜率优化)

    1010: [HNOI2008]玩具装箱toy 题目:传送门 题解: 很明显的一题动态规划... f[i]表示1~i的最小花费 那么方程也是显而易见的:f[i]=min(f[j]+(sum[i]-su ...

  5. thinkphp5项目--个人博客(四)

    thinkphp5项目--个人博客(四) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  6. FZOJ--2214--Knapsack problem(背包)

    Problem 2214 Knapsack problem Accept: 5    Submit: 8 Time Limit: 3000 mSec    Memory Limit : 32768 K ...

  7. Lists and strings

    A string is a sequence of characters and a list is a sequence of values, but a list of characters is ...

  8. POJ 2373 单调队列优化DP

    题意: 思路: f[i] = min(f[j]) + 1; 2 * a <= i - j <= 2 *b: i表示当前在第i个点.f[i]表示当前最少的线段个数 先是N^2的朴素DP(果断 ...

  9. jquery判断页面元素是否存在

    在传统的Javascript里,当我们对某个页面元素进行某种操作前,最好先判断这个元素是否存在.原因是对一个不存在的元素进行操作是不允许的. 例如: document.getElementById(& ...

  10. HD-ACM算法专攻系列(2)——Rightmost Digit

    题目描述: 源码: /**/ #include"iostream" using namespace std; int main() { int t, mod; long long ...