求助 P1020
  • 板块学术版
  • 楼主szhqwq
  • 当前回复9
  • 已保存回复9
  • 发布时间2022/7/8 16:40
  • 上次更新2023/10/27 21:28:45
查看原帖
求助 P1020
638084
szhqwq楼主2022/7/8 16:40

本人马上绿名

求助--->P1020

本人100分代码(满分两百)

记录详情

代码

#include <bits/stdc++.h>
using namespace std;

const int N=5e4+10;

int n;
int h[N],f[N],q[N];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	string line;
	getline(cin,line);
	stringstream sin(line);
	while(sin>>h[n]) n++;
	int res=0,cnt=0;
	for(int i=0;i<n;i++){
		f[i]=1;
		for(int j=0;j<i;j++)
			if(h[i]<=h[j])
				f[i]=max(f[i],f[j]+1);
		res=max(res,f[i]);
		int k=0;
		while(k<cnt && q[k]<h[i]) k++;
		if(k==cnt) q[cnt++]=h[i];
		else q[k]=h[i];
	}
	cout<<res<<endl;
	cout<<cnt<<endl;
	return 0;
}

感谢!!!

欢迎互关

2022/7/8 16:40
加载中...