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分。