求助!!!悬n关!求在代码上改!

B4005 [GESP202406 四级] 黑白方块

BlackWuKong @ 2024-09-03 13:39:34

#include<bits/stdc++.h>
using namespace std;
int n,m,ans=0; 
struct node{
    char num;
    int qs;
}a[15][15];
int main(){
    cin>>n>>m;
    for (int i=1;i<=n;i++){
        for (int j=1;j<=m;j++){
            cin>>a[i][j].num;
            if (j!=1) a[i][j].qs=a[i][j-1].qs+(a[i][j].num-'0');
            else a[i][j].qs=a[i-1][m].qs+(a[i][j].num-'0');
        }
    }
    for (int i=1;i<=n;i++){
        for (int j=1;j<=m;j++){
            for (int x=1;x<=n;x++){
                for (int y=1;y<=m;y++){
                    if (a[i][j].qs-a[x][y].qs==(m-j+1)*(n-x+1)/2) ans=max(ans,(m-j+1)*(n-x+1));
                }
            }
        }
    } 
    cout<<ans;
    return 0;
}

by Yxy7952 @ 2024-09-03 15:05:41

@lanlingxuan

额,我是真看不懂,能不能加点注释


by BlackWuKong @ 2024-09-03 15:06:16

我知道哪里错了,不应该用前缀和


by BlackWuKong @ 2024-09-03 15:07:00

用了就漏减去了一些


by BlackWuKong @ 2024-09-03 15:07:35

@Yxy7952 感谢 大神!


上一页 |