为啥60捏
查看原帖
为啥60捏
1180849
Study_zzy楼主2023/11/5 20:09
#include <iostream>
using namespace std;

int s[20], b[20], f[20];
int n, j, c = 1, y, ans = 2e9;	
void dfs(int x){
	if(x < n)
		for(int i = x; i <= n; i++)
			if(!f[i]){
				c *= s[i];
				y += b[i];
				ans = min(ans, abs(c - y));
				f[i] = 1;	
				dfs(x + 1);
				
				f[i] = 0;
				c /= s[i];
				y -= b[i];
			}
}

int main(){
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> s[i] >> b[i];
	dfs(1);
	cout << ans << endl;
	return 0;
}
2023/11/5 20:09
加载中...