求助:为什么最后一个点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 rnf5114 @ 2023-08-09 20:45:06

@Woodenpickaxe f数组小了,记得开long long还有


by rnf5114 @ 2023-08-09 20:46:28

无耻的求关


by Little_Wooden @ 2023-08-09 20:51:16

@rnfmabj5114 谢谢,关注了


by Weizhuo_Zhao @ 2023-08-09 20:51:44

@rnfmabj5114 开O2+long long还是不行,有WA80pts


by Weizhuo_Zhao @ 2023-08-09 20:52:03

@Woodenpickaxe 不对,开longlong不行


by rnf5114 @ 2023-08-09 20:52:27

@Weizhuo_Zhao 数组也要调啊


by rnf5114 @ 2023-08-09 20:52:50

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int n;
    cin >> n;
    int a[10000];
    for(int i = 1;i <= n;i++){
        cin >> a[i];
    }
    int f[5010];
    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 Little_Wooden @ 2023-08-09 20:53:09

@Weizhuo_Zhao 开long long了,然后把f数组往大开就过了


by Little_Wooden @ 2023-08-09 20:53:32

@rnfmabj5114 如果可以的话看看我主页,谢谢


by Weizhuo_Zhao @ 2023-08-09 20:56:23

@rnfmabj5114 开小RE,开大MLE,怎么要调了


| 下一页