WA #3 #5 求助!
查看原帖
WA #3 #5 求助!
510555
ImposterAnYu楼主2021/9/4 13:56

下载了 #3 的数据后发现,我的代码没有取走最后一行的那个 2,怎么改啊?

#include<bits/stdc++.h>
using namespace std;
int n,x,y,l,a[14][14],i,j,xx[35],yy[35],xxx[35],yyy[35],s,ss,sss,ssss,jls;
void anyu(int x,int y){
	if(x > n || y > n){
		return ;
	}
	if(x == n && y == n){
		if(ss > sss){
			sss = ss;
			jls = s;
			for(int i = 1; i <= s; i++){
				xxx[i] = xx[i];
				yyy[i] = yy[i];
			}
		}
	}
	if(a[x][y]){
		s++;
		ss += a[x][y];
		xx[s] = x;
		yy[s] = y;
	}
	anyu(x + 1,y);
	ss -= a[x + 1][y];
	s -= (a[x + 1][y] > 0);
	anyu(x,y + 1);
	ss -= a[x][y + 1];
	s -= (a[x][y + 1] > 0);
	return ;
}
int main(){
	ios::sync_with_stdio(false);
    cin >> n;
    x = y = l = 1;
    while(x || y || l){
    	cin >> x >> y >> l;
    	a[x][y] = l;
    }
    /*for(i = 1; i <= n; i++){
    	for(j = 1; j <= n; j++){
    		cout<< setw(3) << a[i][j] ;
    	}
    	cout<< endl;
    }*/
    anyu(1,1);
    ssss += sss;
    for(i = 1; i <= jls; i++){
    	a[xxx[i]][yyy[i]] = 0;
    }
    s = ss = sss = 0;
    anyu(1,1);
    ssss += sss;
    for(i = 1; i <= jls; i++){
    	a[xxx[i]][yyy[i]] = 0;
    }
    cout<< endl;
    /*for(i = 1; i <= n; i++){
    	for(j = 1; j <= n; j++){
    		cout<< setw(3) << a[i][j] ;
    	}
    	cout<< endl;
    }*/
    cout<< ssss << endl;
    return 0;
}
2021/9/4 13:56
加载中...