社区讨论

二维dp72分,请问是逻辑问题还是数据问题?

P1004[NOIP 2000 提高组] 方格取数参与者 3已保存回复 2

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
2 条
当前快照
1 份
快照标识符
@m4iu0l8w
此快照首次捕获于
2024/12/11 03:05
去年
此快照最后确认于
2025/11/04 13:01
4 个月前
查看原帖
CPP
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
using namespace std;

int form[11][11] = {};
int max_all[11][11] = {};

void empty_num(int x,int y)
{
    if(x==0&&y==0)
    {
        return;
    }
    else
    {
        if(x>0&&max_all[x][y] - form[x][y] == max_all[x-1][y])
        {
            form[x][y] = 0;
            empty_num(x-1,y);
        }
        else if(y>0&&max_all[x][y] - form[x][y] == max_all[x][y-1])
        {
            form[x][y] = 0;
            empty_num(x,y-1);
        }
    }

};

int main() 
{
    int num;
    int max_nu;
    cin>>num;
    int flag = 1;
    int temp_x, temp_y,temp_num;
    while(flag)
    {
        scanf("%d %d %d",&temp_x,&temp_y,&temp_num);
        form[temp_x][temp_y] = temp_num;
        max_all[temp_x][temp_y] = temp_num;
        if(temp_x==0||temp_y==0)
        {
            form[temp_x][temp_y] = 0;
            max_all[temp_x][temp_y] = 0; 
        }
        if(temp_num==0&&temp_x==0&&temp_y==0)
        {
            flag = 0;
        }
    }
    
    for(int i = 1;i  <= num;i++)
    {
        for(int j = 1;j <= num;j++)
        {
            if (i == 1)
                max_all[i][j] += max_all[i][j-1];
            else if (j == 1)
                max_all[i][j] += max_all[i-1][j];
            else
                max_all[i][j] += max(max_all[i-1][j], max_all[i][j-1]);

        }
    }
    max_nu = max_all[num][num];
    empty_num(num,num);
    for(int i = 1;i  <= num;i++)
    {
        for(int j = 1;j <= num;j++)
        {
            if (i == 1)
                form[i][j] += form[i][j-1];
            else if (j == 1)
                form[i][j] += form[i-1][j];
            else
                form[i][j] += max(form[i-1][j], form[i][j-1]);

        }
    }
    max_nu += form[num][num];
    cout<<max_nu<<endl;
    return 0;
}

回复

2 条回复,欢迎继续交流。

正在加载回复...