其他分享
首页 > 其他分享> > 蓝桥杯填空题分配口罩

蓝桥杯填空题分配口罩

作者:互联网

 代码:

#include<iostream>
 #include<algorithm> 
 #include<cmath>
 using namespace std;
 
 int kz[20];
 int ans =0x3f3f3f3f;
 
 void dfs(int i,int s1,int s2)
 {
 	
	if(i>15){
		ans = min(ans,abs(s1-s2));
		return ; 
	}
	dfs(i+1,s1+kz[i+1],s2);
	dfs(i+1,s1,s2+kz[i+1]);
 }
 int main()
 {
 	for(int i =1;i<=15;i++)
 		cin>>kz[i];
 	long long s1 = 0;
	long long s2 = 0;
 	dfs(1,s1+kz[1],s2);
 	dfs(1,s1,s2+kz[1]);
 	cout<<ans;
 	return 0;
 }

标签:口罩,int,s2,填空题,dfs,蓝桥,long,kz,s1
来源: https://blog.csdn.net/shan1956/article/details/123229496