谁能告诉我这是怎么回事

P1508 Likecloud-吃、吃、吃

```cpp #include<bits/stdc++.h> using namespace std; int n,m,a[210][210],ans=-9999,add; bool b[210][210]; int main() { cin>>n>>m; for(int i=1;i<=n;i++) a[i][0]=-9999; for(int i=1;i<=n;i++) a[i][m+1]=-9999; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin>>a[i][j]; b[n+1][m/2+1]=1; for(int i=n;i>0;i--) for(int j=1;j<=m;j++) if(b[i+1][j-1]||b[i+1][j]||b[i+1][j+1]) b[i][j]=1; else a[i][j]=-9999; /* for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) cout<<b[i][j]<<" "; cout<<"\n"; }*/ for(int i=n;i>0;i--) for(int j=1;j<=m;j++) if(b[i][j]) { add=max(a[i+1][j],max(a[i+1][j-1],a[i+1][j+1])); a[i][j]+=add; } for(int i=1;i<=m;i++) ans=max(ans,a[1][i]); cout<<ans; return 0; } ``` @IlIlIlIlIl数组开小了,可能会RE
by lugaoxiang1205 @ 2024-10-22 18:16:20


@[IlIlIlIlIl](/user/1264592)
by lugaoxiang1205 @ 2024-10-22 18:35:30


|