求助:为什么最后一个点WA了?

B3637 最长上升子序列

Little_Wooden @ 2023-08-09 20:42:51

rt,这是代码

#include <bits/stdc++.h>
using namespace std;
//最长上升子序列
//用动态规划得到答案 
int main(){
    int n;
    cin >> n;
    int a[10000];
    for(int i = 1;i <= n;i++){
        cin >> a[i];
    }
    int f[1000];
    int ans = 0;
    for(int i = 1;i <= n;i++){
        f[i] = 1;
        for(int j = 1;j < i;j++){
            if(a[j] < a[i]){
                f[i] = max(f[i],f[j] + 1);
            }
        }
        ans = max(ans,f[i]);
    }
    cout << ans;
}

by Weizhuo_Zhao @ 2023-08-09 21:00:00

@Woodenpickaxe

#include<bits/stdc++.h>
using namespace std;int main(){long long n;cin>>n;long long a[1000005];for(int i=1;i<=n;i++){cin>>a[i];}long long f[1000005];int ans=0;for(int i=1;i<=n;i++){f[i]=1;for(int j=1;j<i;j++){if(a[j]<a[i]){f[i]=max(f[i],f[j]+1);}}ans=max(ans,f[i]);}cout<<ans;return 0;}

压行代码...


by Little_Wooden @ 2023-08-09 21:00:41

@Weizhuo_Zhao 鹅鹅鹅


by Weizhuo_Zhao @ 2023-08-09 21:02:27

@Woodenpickaxe C++压行机:很多好玩,我整理的,都在我主页!


by rnf5114 @ 2023-08-09 21:22:19

@Weizhuo_Zhao 哪有向你开这么大的


by Weizhuo_Zhao @ 2023-08-09 21:29:15

@rnfmabj5114 ...不是10^6吗?


by rnf5114 @ 2023-08-09 21:33:50

@Weizhuo_Zhao 你有眼睛吗


by rnf5114 @ 2023-08-09 21:34:02

10^6是数值


by rnf5114 @ 2023-08-09 21:34:27

5000才是数组的大小


by Weizhuo_Zhao @ 2023-08-09 21:36:35

@rnfmabj5114 眼瞎


by Evelyn_wsx_star @ 2023-08-10 15:46:22

要long long


上一页 |