题意:和最长滑雪路径一样,

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#define mod=1e9+7;
using namespace std; typedef long long LL;
const int maxn=;
int g[maxn][maxn],vis[maxn][maxn],d[maxn][maxn];
int dir[][]={-,,,,,-,,};
int n,m; int dfs(int x,int y){
if(d[x][y]) return d[x][y];//如果已经搜过这一点,则直接返回,不用再重复计算
int ans=;
for(int i=;i<;i++){ //四个 方向搜
int nx=x+dir[i][];
int ny=y+dir[i][];
if(nx<||nx>n||ny<||ny>m) continue;//越界
if(g[x][y]>g[nx][ny])
ans=max(ans,+dfs(nx,ny));
} if(ans==) return d[x][y]=;
return d[x][y]=ans;
} int main(){
int ncase,r,c;
char s[maxn];
scanf("%d",&ncase);
while(ncase--){
cin>>s;
cin>>n>>m; for(int i=;i<=n;i++)
for(int j=;j<=m;j++) cin>>g[i][j]; memset(d,,sizeof(d));
int tmp=; for(int i=;i<=n;i++){
for(int j=;j<=m;j++)
tmp=max(tmp,dfs(i,j));
}
printf("%s: %d\n",s,tmp);
}
return ;
}

唉= =自己又敲一遍= =运行出来是错的,还对照着以前写的

真是挫爆了= =以后就算不会,也要自己敲一敲 加油--- go---go--go

UVa 10285 Longest Run on a Snowboard【记忆化搜索】的更多相关文章

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

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

  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 - 记忆化搜索

    记忆化搜索,完事... Code /** * UVa * Problem#10285 * Accepted * Time:0ms */ #include<iostream> #includ ...

  4. UVa 10285 - Longest Run on a Snowboard

    称号:给你一个二维矩阵,找到一个点.每一个可以移动到的位置相邻的上下,求最长单调路径. 分析:贪婪,dp.搜索. 这个问题是一个小样本,我们该怎么办. 这里使用贪心算法: 首先.将全部点依照权值排序( ...

  5. UVA - 10285 Longest Run on a Snowboard (线性DP)

    思路:d[x][y]表示以(x, y)作为起点能得到的最长递减序列,转移方程d[x][y] = max(d[px][py] + 1),此处(px, py)是它的相邻位置并且该位置的值小于(x, y)处 ...

  6. UVA - 10285 Longest Run on a Snowboard(最长的滑雪路径)(dp---记忆化搜索)

    题意:在一个R*C(R, C<=100)的整数矩阵上找一条高度严格递减的最长路.起点任意,但每次只能沿着上下左右4个方向之一走一格,并且不能走出矩阵外.矩阵中的数均为0~100. 分析:dp[x ...

  7. UVA 825 Walking on the Safe Side(记忆化搜索)

      Walking on the Safe Side  Square City is a very easy place for people to walk around. The two-way ...

  8. uva 10581 - Partitioning for fun and profit(记忆化搜索+数论)

    题目链接:uva 10581 - Partitioning for fun and profit 题目大意:给定m,n,k,将m分解成n份,然后依照每份的个数排定字典序,而且划分时要求ai−1≤ai, ...

  9. 【UVA 437】The Tower of Babylon(记忆化搜索写法)

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

随机推荐

  1. android studio 智能提示忽略大小写

    Step1: Step2:

  2. 编写一个函数,接受三个string参数,s,oldVal和newVal。使用迭代器及insert和erase函数将s中所有oldVal替换为newVal。测试你的程序,用他替换通用的简写形式,如,将“tho”,将“”“”

    // test14.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...

  3. js冒泡事件的特例toggle无法实现阻止冒泡——slideDown()和slideUp()

    一.问题 题目及答案展示:要求,点击题目,展开答案.如下: 展开前 展开后 最开始使用的toggle方法来实现 $(".content_problem").toggle( func ...

  4. PHP之XML节点追加操作讲解

    问题: 最近研究了xml,我想知道,如何用php向已有的xml文档中添加新的节点,比如,xml文档内容如下,并保存为information.xml: <?xml version="1. ...

  5. 国产神通数据库操作备忘(Linux)

    最近接触到国产神通数据库的一个项目,发现这个数据库还是挺有技术含量的,看起来做的还不错. 1.启动停止 在终端窗口中输入以下命令启动数据库: # /etc/init.d/oscardb_<数据库 ...

  6. Tutorial: Model

    What is a model? Across the internet the definition of MVC is so diluted that it's hard to tell what ...

  7. POJ 2253 Frogger (求某两点之间所有路径中最大边的最小值)

    题意:有两只青蛙,a在第一个石头,b在第二个石头,a要到b那里去,每种a到b的路径中都有最大边,求所有这些最大边的最小值.思路:将所有边长存起来,排好序后,二分枚举答案. 时间复杂度比较高,344ms ...

  8. struts2-2.3.4.1的struts-default.xml源码

    <?xml version="1.0" encoding="UTF-8" ?> <!-- /* * $Id: struts-default.x ...

  9. lintcode:Plus One 加一

    题目: 加一 给定一个非负数,表示一个数字数组,在该数的基础上+1,返回一个新的数组. 该数字按照大小进行排列,最大的数在列表的最前面. 样例 给定 [1,2,3] 表示 123, 返回 [1,2,4 ...

  10. AE数据加载

    1. 数据加载问题: 任何系统都离不开数据的加载,下边就AE中几种常用的数据加载做一个列举.以便查阅: 1.加载个人数据库 个人数据库是保存在Access中的数据库.其加载方式有两种:通过名字和通过属 ...