问个问题
  • 板块学术版
  • 楼主gghack_Nythix
  • 当前回复6
  • 已保存回复6
  • 发布时间2024/3/28 21:04
  • 上次更新2024/3/29 00:14:14
查看原帖
问个问题
895690
gghack_Nythix楼主2024/3/28 21:04

rt,我求LIS有两种代码:

#include <bits/stdc++.h>
#define int long long
using namespace std;
int a[2000005],dp[2000005],cnt,n,k,lst;
void getlis() {
	cnt = 0;
	for(int i = 1;i <= n;++i){
		if(a[i] > dp[cnt])dp[++cnt] = a[i],lst = i;
		else dp[upper_bound(dp + 1,dp + cnt + 1,a[i]) - dp] = a[i];
	}
}
signed main(){
	cin >> n >> k;
	for(int i = 1;i <= n;++i)cin >> a[i];
	getlis();
	cout << cnt << '\n';
}

和:

#include <bits/stdc++.h>
#define int long long
using namespace std;
int a[2000005],dp[2000005],cnt,n,k,lst;
void getlis() {
	cnt = 0;
	for(int i = 1;i <= n;++i){
		if(a[i] > dp[cnt])dp[++cnt] = a[i],lst = i;
		else dp[lower_bound(dp + 1,dp + cnt + 1,a[i]) - dp] = a[i];
	}
}
signed main(){
	cin >> n >> k;
	for(int i = 1;i <= n;++i)cin >> a[i];
	getlis();
	cout << cnt << '\n';
}

请问这两种方法哪个是对的?我测试模板题两者都能通过。但是在P8776中第一种只有80分。

2024/3/28 21:04
加载中...