求大佬帮忙看看
查看原帖
求大佬帮忙看看
258694
PP00544楼主2022/2/8 20:43
#include <bits/stdc++.h>
using namespace std;
int n;
int mp[9+10][9+10];
int a,b,c,cnt1,cnt2,maxn;
void dfs(int x,int y){
	if(x==n && y==n){
		cout<<cnt1<<" "<<cnt2<<endl;
		return ;
	} 
	if(x>n || y>n) return ;
	int ls1=mp[x+1][y];
	int ls2=mp[x][y+1];
	cnt1+=mp[x+1][y];
	cnt2+=mp[x][y+1];
	mp[x+1][y]=0;
	mp[x][y+1]=0;
	
	dfs(x+1,y);
	dfs(x,y+1);
	
	cnt1-=ls1;
	cnt2-=ls2;
	mp[x+1][y]=ls1;
	mp[x][y+1]=ls2;
	return ;
}
int main(){
	cin>>n;
	while(1){
		cin>>a>>b>>c;
		if(a==0 && b==0 && c==0) break;
		mp[a][b]=c;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cout<<mp[i][j]<<" ";
		}
		cout<<endl;
	}
	cnt1=mp[1][1];
	cnt2=mp[1][1];
	dfs(1,1);
	//cout<<maxn<<endl;
	return 0;
}

2022/2/8 20:43
加载中...