练习跳板
一、斐波那契数列
二、记忆化搜索
1、无后效性:某个状态后面的选择与前面没有关系
2、最优子结构:依赖特定问题和子问题的分割方式而成立的条件。各子问题具有最优解,就能求出整个问题的最优解,此时条件成立。
三、模板(练习)
#include<bits/stdc++.h>
using namespace std;
int f[105][105];
int ans = 0;
int a[105][105];
const int dx[4] = {1 , -1 , 0 , 0};
const int dy[4] = {0 , 0 , -1 , 1};
int r , c;
int dfs(int x , int y){
if(f[x][y] > 0){
return f[x][y];
}
int res = 1;
for(int i = 0;i < 4;i++){
int tx = x + dx[i];
int ty = y + dy[i];
if(tx >= 0 and tx < r and ty >= 0 and ty < c and a[x][y] > a[tx][ty]){
res = max(res , dfs(tx , ty) + 1);
}
}
f[x][y] = res;
return res;
}
int main(){
cin >> r >> c;
for(int i = 0;i < r;i++){
for(int j = 0;j < c;j++){
cin >> a[i][j];
}
}
for(int i = 0;i < r;i++){
for(int j = 0;j < c;j++){
ans = max(ans , dfs(i , j));
}
}
cout << ans;
return 0;
}