记忆化搜索 后三个点WA求助
查看原帖
记忆化搜索 后三个点WA求助
905957
Serend1pity楼主2023/11/25 17:27
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
vector<int>memo(5003,-1);
int dfs(int pos,vector<int>&nums){
    int n = nums.size() - 1;
    if(memo[pos] != -1) return memo[pos];
    if(pos == n) return memo[n] = 1;
    int tmax = 0;
    for( int j = pos + 1;j <= n;j++){
        if(nums[j] > nums[pos])
        tmax = max(tmax,dfs(j,nums));
    }
    return memo[pos] = tmax+1;
}
int main(){
    int n;
    cin >> n;
    vector<int>nums(n+1);
    for(int i = 1;i <= n;i++){
        cin >> nums[i];
    }
    cout << dfs(1,nums) << endl;
    return 0;
}
2023/11/25 17:27
加载中...