zoukankan      html  css  js  c++  java
  • 滑雪[dp]

    在这里插入图片描述

    #include <iostream>
    #include <string>
    #include <math.h>
    #include<algorithm>
    #include<cstdio>
    #include<string.h>
    using namespace std;
    int f[105][105];
    int a[105][105];
    struct Node
    {
    	int x;
    	int y;
    	int h;
    }node[10005];
    bool cmp(Node a, Node b)
    {
    	return a.h < b.h;
    }
    int main()
    {
    	int r, c, ans = 0;
    	cin >> r >> c;
    	for (int i = 0; i < r; i++)
    	{
    		for (int j = 0; j < c; j++)
    		{
    			cin >> a[i][j];
    			node[i * c + j].h = a[i][j];
    			node[i * c + j].x = i;
    			node[i * c + j].y = j;
    			f[i][j] = 1;
    		}
    	}
    	sort(node, node + r * c, cmp);
    	for (int i = 0; i < r * c; i++)
    	{
    		int r1 = node[i].x;
    		int c1 = node[i].y;
    		if (r1 > 0 && a[r1][c1] > a[r1 - 1][c1])
    		{
    			f[r1][c1] = max(f[r1][c1], f[r1 - 1][c1] + 1);
    		}
    		if (c1 > 0 && a[r1][c1] > a[r1][c1-1])
    		{
    			f[r1][c1] = max(f[r1][c1], f[r1][c1-1] + 1);
    		}
    		if (r1+1<r && a[r1][c1]>a[r1 + 1][c1])
    		{
    			f[r1][c1]= max(f[r1][c1], f[r1+1][c1] + 1);	
    		}
    		if (c1 + 1 < c && a[r1][c1] > a[r1][c1+1])
    		{
    			f[r1][c1] = max(f[r1][c1], f[r1][c1+1] + 1);
    		}
    	}
    	for (int i = 0; i < r; ++i)
    	{
    		for (int j = 0; j < c; ++j)
    		{
    			ans = max(ans, f[i][j]);
    		}
    	}
    	cout << ans << endl;
    	return 0;
    
    }
    
  • 相关阅读:
    axios 封装
    Git 常用命令行
    React Native 开发环境搭建
    React Native 组件分类
    日期插件rolldate.js的使用
    单图片上传
    使用css完成物流进度的样式
    搜索过滤 以及排序
    v-for的使用方法
    v-if 和v-show 用法
  • 原文地址:https://www.cnblogs.com/Hsiung123/p/13811932.html
Copyright © 2011-2022 走看看