#88分求助(最后一个RE)

P1216 [USACO1.5] [IOI1994]数字三角形 Number Triangles

Abu_Dumbledore @ 2023-09-02 17:59:34

代码如下,望大佬指点,谢谢

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

by Joker_lazydoghead @ 2023-09-02 18:09:43

数组开小了,至少要开到1001,因为数组的下标是从0开始的


by MoYi__666 @ 2023-09-02 18:10:53

b数组开大一点 到1145就够了(


by Joker_lazydoghead @ 2023-09-02 18:11:59

@MoYi__666 a也要开大啊


by Abu_Dumbledore @ 2023-09-02 18:14:22

@lazy_doghead 可以了,谢谢


by Abu_Dumbledore @ 2023-09-02 18:16:39

AC了,感谢所有大佬的指点,谢谢!(本贴终)


by wym_2012 @ 2023-10-06 12:09:40

@MoYi__666 好臭的数组


|