其他分享
首页 > 其他分享> > AcWing 1027. 方格取数

AcWing 1027. 方格取数

作者:互联网

明天补思路
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define fr first
#define se second

typedef pair<int, int> PII;
typedef unsigned long long ULL;

const int INF = 0X3f3f3f3f, N = 20, MOD = 1e9 + 10;

int w[N][N];
int f[2*N][N][N];

void work() {
    int n;
    cin>>n;
    
    int a,b,c;
    while(cin>>a>>b>>c,a||b||c) w[a][b]=c;

    for(int k=2;k<=2*n;k++){
        for(int i1=1;i1<=n;i1++)
            for(int i2=1;i2<=n;i2++){
                int j1=k-i1,j2=k-i2;
                if(j1 && j2 && j1<=n && j2<=n){
                    int t=w[i1][j1];
                    if(i1!=i2) t+=w[i2][j2];
                    // cout<<t<<endl;
                    int &x=f[k][i1][i2];
                    x=max(x,f[k-1][i1][i2]+t);
                    x=max(x,f[k-1][i1-1][i2]+t);
                    x=max(x,f[k-1][i1][i2-1]+t);
                    x=max(x,f[k-1][i1-1][i2-1]+t);
                }
            }
    }
    
    cout<<f[2*n][n][n]<<endl;

}

signed main() {
	
	work();

	return 0;
}

标签:1027,int,typedef,long,cin,取数,MOD,AcWing,define
来源: https://www.cnblogs.com/xhy666/p/16407358.html