dp[

i][j]=max(四个方向点)+1; 四个方向上的点应该存在,且大于i,j,表示以i,j开始的点最长路径,递归的结束条件不用判断,因为

dp[][]最大数位置肯定 直接结束,随后次大值肯定能结束,以此类推,所以可以执行,但自下而上动态规划不好写。因为要确定这些数的大小,麻烦。

 
 
#include<iostream>
#include<memory.h>
using namespace std;
int dp[101][101];
int arr[101][101];
int c;
int r;
int x[]={0,1,0,-1}; int y[]={1,0,-1,0}; bool isvalid(int row,int col,int r_off,int c_off) //找到没有超过矩阵范围,且在点比arr[i][j]大
{
int newr=row+r_off;
int newc=col+c_off;
if(newr>=0&&newr<r&&newc>=0&&newc<c&&arr[row][col]<arr[newr][newc])
{
return true; } return false; } int fun(int row,int col)
{
int tem=0;
for(int i=0;i<4;i++)
{
if(isvalid(row,col,x[i],y[i]))
{
int tfun=fun(row+x[i],col+y[i]);
if(tem<tfun)
{
tem=tfun;
} } }
return tem+1; }
//备忘录,自顶向下动态规划,dp矩阵防止重复计算
int fun2(int row,int col)
{
if(dp[row][col]>0) return dp[row][col];
int tem=0;
for(int i=0;i<4;i++)
{
if(isvalid(row,col,x[i],y[i]))
{
int tfun=fun(row+x[i],col+y[i]);
dp[row+x[i]][col+y[i]]=tfun;
if(tem<tfun)
{
tem=tfun;
} } }
return tem+1; }
int main()
{
int len;
cin>>len;
while(len--)
{
memset(dp,0,sizeof(dp)); cin>>r>>c;
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
cin>>arr[i][j]; } }
int max=0;
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
int tem= fun2(i,j); //以i,j为开始的最长点数
if(max<tem) max=tem; } } cout<<max<<endl; } return 0; }

nyoj10 滑雪的更多相关文章

  1. tyvj1004 滑雪

    描述     trs喜欢滑雪.他来到了一个滑雪场,这个滑雪场是一个矩形,为了简便,我们用r行c列的矩阵来表示每块地形.为了得到更快的速度,滑行的路线必须向下倾斜.    例如样例中的那个矩形,可以从某 ...

  2. bzoj 2753: [SCOI2012] 滑雪与时间胶囊 Label:MST

    题目描述 a180285非常喜欢滑雪.他来到一座雪山,这里分布着M条供滑行的轨道和N个轨道之间的交点(同时也是景点),而且每个景点都有一编号i(1<=i<=N)和一高度Hi.a180285 ...

  3. USACO 2014 JAN 滑雪录像

    2. 滑雪录像{silver题3} [问题描述] 冬奥会的电视时刻表包含N (1 <= N <= 150)个节目,每个节目都有开始和结束时间.农民约翰有两台录像机,请计算他最多可以录制多少 ...

  4. USACO 滑雪课程

    #include<cstdio> #include<iostream> using namespace std; int T,S,N,maxd; ],lv[],next[],f ...

  5. Bzoj2753 [SCOI2012]滑雪与时间胶囊

    2753: [SCOI2012]滑雪与时间胶囊 Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 2282  Solved: 796 Descriptio ...

  6. 滑雪 why WA

    滑雪 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 587  Solved: 219 Description 小明喜欢滑雪,因为滑雪的确很刺激,可是为了获 ...

  7. 滑雪(简单dp)

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 81099   Accepted: 30239 Description Mic ...

  8. Code[VS] 2152 滑雪题解

    Code[VS] 2152 滑雪题解 题目描述 Description trs喜欢滑雪.他来到了一个滑雪场,这个滑雪场是一个矩形,为了简便,我们用r行c列的矩阵来表示每块地形.为了得到更快的速度,滑行 ...

  9. E - 滑雪

    Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Pract ...

随机推荐

  1. 学习PYTHON第一天

    需要掌握的内容 1.编程语言 2.python   .  C#   JAVA 3.python:  pypy    cpython     jpython 4.执行方式 解释器 文件执行 5.指定解释 ...

  2. nodejs基础安装

    安装Nodejs需要从官网上下载一个最新的安装包,运行.我这里是win764位系统. 下载版本6.5.0 由于去外国的镜像上下载东西比较慢,淘宝为我们准备了国内的镜像.我们需要安装国内镜像的使用工具. ...

  3. 常用DOS命令参数详解

    一.DIR命令的格式: dir [D:][PATH][NAME][[/A][:attrib]][/o:[sorted][/s][/b][/l][/c[h] (1)dir /a:attrib 缺省包含所 ...

  4. Spring中的一个错误:使用Resources时报错(The annotation @Resources is disallowed for this location)

    在学习Spring的过程中遇到一个错误:在使用注解@resources的时候提示:The annotation @Resources is disallowed for this location 后 ...

  5. Oracle----date

    to_date('december 31, 2008, 11:30 p.m.', 'Month dd, YYYY, HH:MI P.M.')

  6. Codeforces Burning Midnight Oil

    /* * BurningMidnightOil.cpp * * Created on: 2013-10-12 * Author: wangzhu */ /** * 每次至少写多少行代码ret: * 1 ...

  7. 坚果云创业团队访谈:我们 DIY 云存储(不要过度关注竞争对手,尤其当我们还是小公司的时候)

    坚果云(http://jianguoyun.com/)是一款用于多平台文件同步.备份和交换的云存储工具,立志于提供“便捷,安全”的服务.坚果云自去年年初启动内测,至今年三月初刚刚正式发布.近日我们拜访 ...

  8. 【HDOJ】4400 Mines

    (1) KD树,但实际没有STL快,3000+ /* 4400 */ #include <iostream> #include <string> #include <ma ...

  9. Case Studies: Retail and Investment Banks Use of Social Media

    The past couple of months have seen an increased acknowledgement of the role social media has to pla ...

  10. Cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or specify proxy interfaces

    问题解决:缺少jar包 cglib-2.1.3.jar