20分,普通深搜,help!
查看原帖
20分,普通深搜,help!
1138325
MC_dream_tsr楼主2024/10/5 13:59
# include<bits/stdc++.h>
using namespace std;
int n, ans = 100000000;
struct p{
	int s, k; 
}a[11];
int book[11];//写完后发现没啥用,当作格式 
void dfs(int step, int sour, int b) { //sour酸度总和,b苦度总和 
	if(step > n) {
		ans = min(abs(sour - b), ans);
		return;
	}
	book[step] = 1;//选 
	dfs(step + 1, sour * a[step].s, b + a[step].k);
	book[step] = 0;
	// 恢复状态位 
	book[step] = 2;//不选 
	dfs(step + 1, sour, b);
	book[step] = 0;
	// 恢复状态位  
}
int main() {
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i].s >> a[i].k;
	dfs(1, 1, 0);
	cout << ans;
	return 0;
}
2024/10/5 13:59
加载中...