我这道题AC的代码被我自己HACK掉了,请求加强数据

P1736 创意吃鱼法

ziiidan @ 2019-09-07 08:00:54

刚刚发到题目总版了,重发一下,麻烦管理员不要删帖

P1736 创意吃鱼法

以下是我这道题AC的代码,发现有后效性:

#include<iostream>
#include<cstdio>

using namespace std;

const int maxn = 2505;

int n, m, ans;
int a[maxn][maxn], b[maxn][maxn], pos[maxn][maxn], f[maxn][maxn], s[maxn][maxn];

inline int read(void)
{
    int s = 0, w = 1;
    char ch = getchar();
    for(; ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') w = -1;
    for(; ch <= '9' && ch >= '0'; ch = getchar()) s = s * 10 + ch - '0';
    return s * w;
}

void DP(void)
{
    for(register int i = 1; i <= n; i++)
    {
        for(register int j = 1; j <= m; j++)
        {
            if(a[i][j])
            {
                if(f[i - 1][j - 1] != 0) 
                {
                    int posx = pos[i - 1][j - 1], posy = pos[i - 1][j - 1] + j - i;
                    int sum = s[i][j] - s[posx - 1][j] - s[i][posy - 1] + s[posx - 1][posy - 1]; 
                    if(sum ==  i - posx + 1) {f[i][j] = f[i - 1][j - 1] + 1; pos[i][j] = pos[i - 1][j - 1]; ans = max(ans, f[i][j]);}
                    else {f[i][j] = 1; pos[i][j] = i; ans = max(ans, f[i][j]);}
                }
                else {f[i][j] = 1; pos[i][j] = i; ans = max(ans, f[i][j]);}
            }
        }
    }
}

int main()
{
    n = read(); m = read();
    for(register int i = 1; i <= n; i++) 
        for(register int j = 1; j <= m; j++)
        {
            a[i][j] = read();
            s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];
        }
    DP();

//  for(register int i = 1; i <= n; i++) {for(register int j = 1; j <= m; j++) cout << f[i][j] << ' '; cout << '\n';}

    for(register int i = 1; i <= n; i++)
        for(register int j = 1; j <= m; j++) 
        {
            b[i][j] = a[i][m - j + 1];
            s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + b[i][j];
        }
    for(register int i = 1; i <= n; i++)
        for(register int j = 1; j <= m; j++) a[i][j] = b[i][j], pos[i][j] = 0;
    DP();

    for(register int i = 1; i <= n; i++)
        for(register int j = 1; j <= m; j++) 
        {
            b[i][j] = a[n - i + 1][j];
            s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + b[i][j];
        }
    for(register int i = 1; i <= n; i++)
        for(register int j = 1; j <= m; j++) a[i][j] = b[i][j], pos[i][j] = 0;
    DP();

    for(register int i = 1; i <= n; i++)
        for(register int j = 1; j <= m; j++) 
        {
            b[i][j] = a[i][m - j + 1];
            s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + b[i][j];
        }
    for(register int i = 1; i <= n; i++)
        for(register int j = 1; j <= m; j++) a[i][j] = b[i][j], pos[i][j] = 0;
    DP();
    cout << ans << '\n'; 
    return 0;
}

HACK数据1:

8 8

1 0 0 1 0 0 0 0

0 1 0 0 0 0 0 0

0 0 1 0 0 0 0 0

0 0 0 1 0 0 0 0

0 0 0 0 1 0 0 0

0 0 0 0 0 1 0 0

0 0 0 0 0 0 1 0

0 0 0 0 1 0 0 1

HACK数据2:

10 10

1 0 0 1 0 0 1 0 0 1

0 1 0 0 0 0 0 0 0 0

0 0 1 0 0 0 0 0 0 0

0 0 0 1 0 0 0 0 0 0

0 0 0 0 1 0 0 0 0 0

0 0 0 0 0 1 0 0 0 0

0 0 0 0 0 0 1 0 0 0

0 0 0 0 0 0 0 1 0 0

0 0 0 0 0 0 0 0 1 0

1 0 0 1 0 0 1 0 0 1

请求加入以上数据或加入类似数据来保证数据强度

@chen_zhe


by huangzhewer @ 2019-09-07 09:07:16

orz%%%%


by ziiidan @ 2019-10-09 09:23:10

@chen_zhe


by derta @ 2020-02-08 16:44:46

%%%


|