玄关求条
查看原帖
玄关求条
1392512
gaoqingze1楼主2025/1/18 10:29
#include<bits/stdc++.h>
using namespace std;
int n,tu[15][15],a[101],b[101],c[101],ans;
int main(){
	cin>>n;
	for(int i=1;;i++){
		cin>>a[i]>>b[i]>>c[i];
		if(a[i]==0&&b[i]==0&&c[i]==0)
			break;
		else
			tu[a[i]][b[i]]=c[i];
	}
	int a1=1,a2=1,a3=1,a4=1;
	ans+=tu[1][1];
	while(a1!=n&&a2!=n&&a3!=n&&a4!=n){
		int maxa1,maxa2,maxb1,maxb2,maxs,s1,s2,s3,s4;
		if(a1==a3+1&&a2+1==a4)
			s1=tu[a1][a2+1];
		else
			s1=tu[a1][a2+1]+tu[a3+1][a4];
		maxa1=a1;maxa2=a3+1;maxb1=a2+1;maxb2=a4;maxs=s1;
		if(a1+1==a3&&a2==a4+1)
			s2=tu[a1+1][a2];
		else
			s2=tu[a1+1][a2]+tu[a3][a4+1];
		if(s2>s1){
			maxa1=a1+1;maxa2=a3;maxb1=a2;maxb2=a4+1;maxs=s2;
		}
		if(a1+1==a3+1&&a2==a4)
			s3=tu[a1+1][a2];
		else
			s3=tu[a1+1][a2]+tu[a3+1][a4];
		if(s3>s2){
			maxa1=a1+1;maxa2=a3+1;maxb1=a2;maxb2=a4;maxs=s3;
		}
		if(a1==a3&&a2+1==a4+1)
			s4=tu[a1][a2+1];
		else
			s4=tu[a1][a2+1]+tu[a3][a4+1];
		if(s4>s3){
			maxa1=a1;maxa2=a3;maxb1=a2+1;maxb2=a4+1;maxs=s4;
		}
		ans+=maxs;a1=maxa1;a2=maxb1;a3=maxa2;a4=maxb2;
	}	
	cout<<ans;
	return 0;
} 


2025/1/18 10:29
加载中...