20分求助

B3637 最长上升子序列

liyanchenlycccccc @ 2023-08-30 10:58:38


#include <bits/stdc++.h>
using namespace std;
int n,a[5010],dp[100010],ans;
int main()
{
  scanf("%d",&n);
  for(int i=1; i<=n; i++)
  {
    scanf("%d",&a[i]);
    dp[i]=1;
  }
  for(int i=1; i<=n; i++)
  {
    for(int j=1; j<n; j++)
    {
      if(a[j]<a[i]&&dp[i]<dp[j]+1)
      {
        dp[i]=dp[j]+1;
      }
      ans=max(ans,dp[i]);
    }
  }
  printf("%d",ans);
  return 0;
}

by Miyamizu_Mitsuha @ 2023-08-30 11:04:48

里层循环应该是j=1,j<i


by tmpliyijiang @ 2023-12-07 23:25:14

14 行改为 for(int j=1;j<i;j++)


|