42分还有救吗?
查看原帖
42分还有救吗?
1303372
Michael_114楼主2024/11/20 17:58
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#define ll long long
using namespace std;
const int maxn = 100;
ll b[maxn][maxn][maxn],a[maxn][maxn],n;
int main()
{
	cin>>n;
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	ll x1,y1,num;
	while(1){
		cin>>x1>>y1>>num;
		if(x1==0&&y1==0&&num==0){
			break;
		}
		a[x1][y1] = num;
	}
	b[2][1][1] = 0;
	for(ll i = 3;i<n+n;i++){
		for(ll x = 1;x<n;x++){
			for(ll y = x+1;y<=n;y++){
				ll t = b[i][x][y];
				t = max(t,b[i-1][x][y]);
				t = max(t,b[i-1][x-1][y]);
				t = max(t,b[i-1][x][y-1]);
				t = max(t,b[i-1][x-1][y-1]);
				if(t==-1){
					continue;
				}
				b[i][x][y] = a[x][i-x]+a[y][i-y]+t;
			}
		}
	}
	cout<<b[n+n-1][n-1][n]<<endl;
	return 0;
}

本蒟蒻玄关2个,先到先得

2024/11/20 17:58
加载中...