大脑死机,紧急求助
查看原帖
大脑死机,紧急求助
1268524
DX3906_ourstar楼主2024/7/17 09:37

已经实现了第一行输出的正确计算(就是求最长不上升子序列长度嘛),但是第二行输出不知道该咋算了……似乎是要在剩余的几个高度里不断求最长不上升子序列然后统计,似乎要用递归……

翻了一遍题解,没有一篇看得懂的……

附上代码:

#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<stack>
#define INF 0x7fffffff
#define int long long
#define re register
#define zhuang_bi ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 
using namespace std;

int h[100005];
int n = 0,maxx = - INF;

int dp[100005];

bool cmp(int a,int b){
	return a > b;
}

signed main(){
	zhuang_bi
	for(re int i = 0;i < 100005;i ++)
		dp[i] = 1;
	do{
		n ++;
	}while(cin>>h[n]);
	n --;
	for(re int i = 1;i <= n;i ++){
		for(re int j = 1;j < i;j ++){
			if(h[i] <= h[j]){
				dp[i] = max(dp[i],dp[j] + 1);
				if(dp[i] > maxx){
					maxx = dp[i];
				}
			}
		}
	}
	cout<<maxx<<"\n";
	return 0;
}
2024/7/17 09:37
加载中...