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. Your branch and 'origin/master' have diverged

    git fetch origin git reset --hard origin/master

  2. Oracle 事务相关的一些测试

    1.sqlplus 客户端正常退出 SQL> desc t; 名称 是否为空? 类型 ----------------------------------------- -------- --- ...

  3. boost 编译

    备份一下,用的时候直接粘贴,免得到处找>_< 32 bjam threading=multi link=static runtime-link=static --stagedir=stag ...

  4. sublime text 2 前端编码神器-快捷键与使用技巧介绍

    介绍网址:http://www.xuanfengge.com/sublime-text-2-artifact.html

  5. easyui源码翻译1.32--Messager(消息窗口)

    前言 使用$.messager.defaults重写默认值对象.下载该插件翻译源码 消息窗口提供了不同的消息框风格,包含alert(警告框), confirm(确认框), prompt(提示框), p ...

  6. 9. MonoBehaviour.StartCoroutine 开始协同程序

    function StartCoroutine (routine : IEnumerator) : Coroutine 描述:开始协同程序. 一个协同程序在执行过程中,可以在任意位置使用yield语句 ...

  7. Android-锁屏功能

    当屏幕多久没有点击的时候,进行某种操作就是所谓的锁屏功能. onCreate: public void addRunnable() { handler.postDelayed(runnable, Co ...

  8. 【HDOJ】5564 Clarke and digits

    DP+快速矩阵幂.注意base矩阵的初始化,不难. /* 5564 */ #include <iostream> #include <string> #include < ...

  9. 归纳决策树ID3(Java实现)

    先上问题吧,我们统计了14天的气象数据(指标包括outlook,temperature,humidity,windy),并已知这些天气是否打球(play).如果给出新一天的气象指标数据:sunny,c ...

  10. 结构体dict_index_t;

    /** InnoDB B-tree index */ typedef struct dict_index_struct dict_index_t; /** Data structure for an ...