1 条题解

  • 1
    @ 2024-12-17 13:32:11
    #include <iostream>
    #include <algorithm>
    using namespace std;
    int a[55][55], f[55][55][55][55];
    inline int read(){
    	int x = 0, f = 1;
    	char c = getchar();
    	while(c < '0'  ||  c > '9'){
    		if(c == '-')
    			f =  - 1;
    		c = getchar();
    	}
    	while(c >= '0'  &&  c <= '9'){
    		x = x * 10 + c - 48;
    		c = getchar();
    	}
    	return x * f;
    }
    int main(){
    	int n = read(), x = read(), y = read(), z = read(); 
        while(x > 0  &&  y > 0  &&  z > 0){
            a[x][y] = z;
            cin >> x >> y >> z;
        }
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= n; j++)
                for(int k = 1; k <= n; k++)
                    for(int l = 1; l <= n; l++){
    						int opt1 = max(f[i - 1][j][k - 1][l], f[i][j - 1][k][l - 1]);
    	                    int opt2 = max(f[i - 1][j][k][l - 1], f[i][j - 1][k - 1][l]);
    	                    f[i][j][k][l] = max(opt1, opt2) + a[i][j];
    	                    if(i != k && j != l)
    							f[i][j][k][l] += a[k][l];
    					}
        cout << f[n][n][n][n] << '\n';
        return 0;
    }
    
    • 1

    信息

    ID
    648
    时间
    1000ms
    内存
    256MiB
    难度
    3
    标签
    递交数
    55
    已通过
    29
    上传者