后面四个RE,求助

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

ZMY_illusion @ 2023-07-12 08:25:44

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

by rnf5114 @ 2023-07-12 08:44:01

@ZMY_illusion 1≤r≤1000


by tankewei911 @ 2023-07-12 09:14:04

数组开大点


by cw_xuan @ 2023-07-26 16:16:46

include<bits/stdc++.h>

using namespace std;

long long n,a[1029][1932],w[2923] [1103],m=-27272288;

int main(){

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++){

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

}

for(int j=1;j<=n;j++)m=max(m,w[n][j]);

cout<<m;

return 0;

}

|