为什么会ce,按道理应该可以拿一半分啊?

P1439 【模板】最长公共子序列

MambaHJ @ 2018-10-29 22:42:19

#include <iostream>
#include <cstdio>
using namespace std;

const int maxn = 100100;

int n, ans[maxn][maxn], a[maxn], b[maxn];

int max(int a, int b){
    return a > b ? a:b;
}

int main(){
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &b[i]);
    for (int i = 0; i <= n; ++i){
        for (int j = 0; j <= n; ++j){
            if ( i == 0 || j == 0){
                ans[i][j] = 0;
                continue;
            }
            if (a[i] == b[j])
                ans[i][j] = ans[i - 1][j - 1] + 1;
            else
                ans[i][j] = max(ans[i][j - 1], ans[i - 1][j]);
        }
    }
    printf("%d\n", ans[n][n]);
    return 0;
}

by _louhc @ 2018-10-29 22:44:29

iostream 中有max函数了,不用再定义了


by Eason_AC @ 2018-10-29 22:44:43

你把评测记录的链接拷过来给我看一下


by Eason_AC @ 2018-10-29 22:45:24

哦,对,max是C++STL库自带函数


by GKxx @ 2018-10-29 22:46:36

@Sinner 不是这个问题 iostream间接引用的std::max是模板函数,根据C++函数匹配规则,非模板函数比模板函数更优,因此这里对max的调用不存在二义性


by 梧桐灯 @ 2018-10-29 22:47:22

@MambaHJ ans数组空间过大


by MambaHJ @ 2018-10-29 22:48:13

@GKxx 是这样


by MambaHJ @ 2018-10-29 22:49:00

@光随影走 我刚试了一下确实这样,开了5000的就可以了。。可是这算是bug嘛,也太玄学了吧


by 梧桐灯 @ 2018-10-29 22:49:29

@MambaHJ 算QAQ,数组太大会报错的QAQ


by MambaHJ @ 2018-10-29 22:49:52

@Eason_AC https://www.luogu.org/record/show?rid=12720804


by MambaHJ @ 2018-10-29 22:50:30

@Sinner 应该不是这个的问题


|