P2392 kkksc03考前临时抱佛脚(洛谷 数据型DFS)

#include
using namespace std;
const int N = 50;
const int INF = 0x3f3f3f3f;

int s1,s2,s3,s4;
int l,r,ans,minn;

int work[N][5];
int s[N];

void DFS(int x,int i){
	
	if(x > s[i]){
		minn = min(minn,max(l,r));
		return;
	}
	
	l += work[x][i];
	DFS(x + 1,i);
	l -= work[x][i];
	
	r += work[x][i];
	DFS(x + 1,i);
	r -= work[x][i];
}

int main(){
	
	cin>>s[1]>>s[2]>>s[3]>>s[4];
	
	for(int i = 1;i <= 4;i++){
		l = 0;
		r = 0;
		minn = INF;
		
		for(int j = 1;j <= s[i];j++)cin>>work[j][i];
		DFS(1,i);
		ans += minn;
	}
	
	cout<<ans; 
} 

你可能感兴趣的:(搜索,洛谷)