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

 #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. html+css学习笔记 4[定位]

    如何让图1中的div2移动到如图2上的位置: 思路:哪些css命令能够影响盒子显示的位置呢? relative相对定位/定位偏移量 position:relative;  相对定位         a ...

  2. 《深入理解javascript原型和闭包系列》 知识点整理(转)

    深入理解javascript原型和闭包系列 对原型和闭包等相关知识的讲解,由浅入深,通俗易懂,每个字都值得细细研究. 一.一切都是对象 1. typeof操作符输出6种类型:string boolea ...

  3. java和javascript真的有关系=。=

    相同点:1. 内存管理,两者都采用GC来对内存进行回收.因此Java与javascript的内存泄露情况十分相似. 2. 代码编译为机器码后由中间件执行:Java使用前会编译为字节码后由JVM执行,V ...

  4. 【系统Configmachine.config与自己的应用程序的App.config/Web.Config配置节点重复】解决方法

    自己的应用程序的App.config或Web.Config文件中与系统的C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Configmachine.co ...

  5. uva 1423 拓扑排序

    刘书上例题  拓扑排序 #include <cstdio> #include <cstdlib> #include <cmath> #include <map ...

  6. HDOJ 1856 More is better

    转自:wutianqi http://www.wutianqi.com/?p=1069 tag:并查集 #include <iostream> using namespace std; # ...

  7. hdu 4696 Answers

    思路:由于c[i]要么是1,要么是2.所以当c[i]中没有1的时候就不可能得到奇数: 再就是如果m<=0,也不可能得到. 代码如下: #include<cstdio> #includ ...

  8. poj 1026 Cipher

    置换群就可以搞定!!! 注意下格式就好了…… #include<iostream> #include<stdio.h> #include<algorithm> #i ...

  9. Android 判断当前联网的类型 wifi、移动数据流量

    先获取系统管理网络连接的Manager: ConnectivityManager connectivityManager = (ConnectivityManager) getSystemServic ...

  10. hadoop:could only be replicated to 0 nodes, instead of 1

    在Hadoop的环境搭建过程中,常常会遇到类似这样的错误信息提示:“could only be replicated to 0 nodes, instead of 1 ”,产生这样的错误原因有多种,这 ...