动态规划_百炼 1088 滑雪

 1 #define _CRT_SECURE_NO_WARNINGS
 2 #include <stdio.h>
 3 #include <math.h>
 4 #include <algorithm>
 5 #include <stdlib.h>
 6 #include <vector>
 7 #include <map>
 8 #include <queue>
 9 #include <string>
10 #include <iostream>
11 #include <ctype.h>
12 #include <string.h>
13 #include <set>
14 #include <stack>
15 #include<functional>
16 using namespace std;
17 #define size 105
18 #define maxn  1<<30
19 int dp[size][size];//以i,j为结尾的线段所滑行的最大距离
20 int a[size][size];
21 int row, col;
22 int go[4][2] = { 1, 0, 0, 1, -1, 0, 0, -1 };
23 int solve(int x, int y){//表示以x,y结尾的点所滑翔的最大距离,从最低点往上收敛
24     if (dp[x][y] != -1) return dp[x][y];
25     int ret = 1;
26     for (int i = 0; i < 4; i++){
27         int tx = x + go[i][0];
28         int ty = y + go[i][1];
29         if (tx < 1 || ty<1 || tx>row || ty>col) continue;
30         if(a[x][y]<a[tx][ty]) ret = max(ret, solve(tx, ty)+1);
31     }
32     dp[x][y] = ret;
33     return ret;
34 }
35 int main(){
36     cin >> row >> col;
37     for (int i = 1; i <= row; i++)
38         for (int j = 1; j <= col; j++){
39             dp[i][j] = -1;
40             cin >> a[i][j];
41         }
42     int ans = 1;
43     for (int i = 1; i <= row; i++)
44         for (int j = 1; j <= col; j++)
45             ans = max(ans, solve( i, j));
46     cout << ans << endl;
47     system("pause");
48     return 0;
49 }

原文地址:https://www.cnblogs.com/MapReduce/p/8367263.html

时间: 2024-07-31 05:14:02

动态规划_百炼 1088 滑雪的相关文章

动态规划_百炼4120 硬币

1 #define _CRT_SECURE_NO_WARNINGS 2 #include <stdio.h> 3 #include <math.h> 4 #include <algorithm> 5 #include <stdlib.h> 6 #include <vector> 7 #include <map> 8 #include <queue> 9 #include <string> 10 #include

动态规划_百炼 4121 股票买卖

1 #define _CRT_SECURE_NO_WARNINGS 2 #include <stdio.h> 3 #include <math.h> 4 #include <algorithm> 5 #include <stdlib.h> 6 #include <vector> 7 #include <map> 8 #include <queue> 9 #include <string> 10 #include

动态规划_百炼4122 切割回文

1 #define _CRT_SECURE_NO_WARNINGS 2 #include <stdio.h> 3 #include <math.h> 4 #include <algorithm> 5 #include <stdlib.h> 6 #include <vector> 7 #include <map> 8 #include <queue> 9 #include <string> 10 #include

动态规划_百炼1664 放苹果

1 #define _CRT_SECURE_NO_WARNINGS 2 #include <stdio.h> 3 #include <math.h> 4 #include <algorithm> 5 #include <stdlib.h> 6 #include <vector> 7 #include <map> 8 #include <queue> 9 #include <string> 10 #include

动态规划_百炼 4117 简单的整数划分问题

1 #define _CRT_SECURE_NO_WARNINGS 2 #include <stdio.h> 3 #include <math.h> 4 #include <algorithm> 5 #include <stdlib.h> 6 #include <vector> 7 #include <map> 8 #include <queue> 9 #include <string> 10 #include

POJ 1088 滑雪 记忆化优化题解

本题有人写是DP,不过和DP还是有点差别的,应该主要是记忆化 Momoization 算法. 思路就是递归,然后在递归的过程把计算的结果记录起来,以便后面使用. 很经典的搜索题目,这种方法很多题目考到的. 关键还是如何把代码写清晰工整了,O(∩_∩)O~. #include <stdio.h> const int MAX_N = 101; int R, C; int arr[MAX_N][MAX_N]; int tbl[MAX_N][MAX_N]; inline int max(int a,

hdu 1088 滑雪

果然书要结合题来看才有效果 通过这题对记忆化搜索有了初步的理解 碰到没有访问过的点 进行搜索 之后记录下该点能滑出的最远距离 碰到搜索过的点 直接加上 dp[i] 就可以了 #include<stdio.h> #include<string.h> #include<math.h> #include<iostream> #include<algorithm> #include<queue> #include<stack> #

poj 1088 滑雪

http://poj.org/problem?id=1088 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 6 int g[200][200]; 7 int dp[200][200]; 8 int r,c; 9 int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}}; 10 int max1=-1; 11 12

[ACM] poj 1088 滑雪 (记忆化搜索DFS)

求n*m网格内矩形的数目[ACM] poj 1088 滑雪 (记忆化搜索DFS),布布扣,bubuko.com