20分—超时求助!!!
查看原帖
20分—超时求助!!!
815373
hu2265005977楼主2024/3/2 19:23
#include<bits/stdc++.h>
using namespace std;
int n,s,t,w,k;
int a[2][61],b[5];
void study(int s,int t){
	if(s<t)
		for(int i=1;i<=n;i++)
			if(a[0][i]==0){
				a[0][i]=1;
				study(s+a[1][i],t);
				a[0][i]=0;
			}
	else{
		k=min(k,s);s=0;return ;
	}
	
}
int main(){
	for(int i=1;i<=4;i++)
		cin>>b[i];
	for(int i=1;i<=4;i++){
		n=b[i];t=0;
		for(int j=1;j<=n;j++){
			cin>>a[1][j];
			t+=a[1][j];
		}
		k=10000;
		t=t/2+t%2;
		study(s,t);
		w+=k;
	}
	cout<<w;
	return 0;
}
//printf("%.2lf",);

样例

2024/3/2 19:23
加载中...