样例正确,只拿44

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

wnsndg @ 2024-02-08 10:34:16

代码:

#include<iostream>
#include<algorithm>
using namespace std;
int a[1001][1001],ans;
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=i;j++){
            cin>>a[i][j];
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=i;j++){
            a[i][j]+=max(a[i-1][j-1],a[i][j-1]);
        }
    }
    for(int i=1;i<=n;i++){
        ans=max(a[n][i],ans);
    }
    cout<<ans<<endl;
    return 0;
}

这个样例过了,但问题出在哪里?

求指正=)


by DevilsFlame @ 2024-02-08 10:45:41

你的状态转移方程错了,你仔细看一下


by DevilsFlame @ 2024-02-08 10:46:36

这竟然还能拿半分


by wnsndg @ 2024-02-08 10:57:39

错哪了


by Chernobog_Belobog @ 2024-02-08 11:14:35

a[i][j] = max(a[i - 1][j - 1] , a[i - 1][j]);


by wnsndg @ 2024-02-08 16:01:58

哦哦哦


by wnsndg @ 2024-02-08 16:02:09

谢谢


by wnsndg @ 2024-02-08 16:02:48

AC了


|