本蒟蒻对序列进行排序,之后用两序列的LCS求解LIS,但subtask1无法通过,求助
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int MAX=5e3+10;
int n;
int v1[MAX],v2[MAX];
int dp[MAX][MAX];
void lcs(){
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(v1[i-1]==v2[j-1]) dp[i][j]=dp[i-1][j-1]+1;
else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
cout<<dp[n][n]<<endl;
}
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n;
for(int i=0;i<n;i++) cin>>v1[i];
copy(v1,v1+n,v2);
sort(v2,v2+n);
lcs();
return 0;
}