洛谷 P2036. [COCI 2008/2009 #2] PERKET
原题链接
中等
作者:
我是java同学
,
2023-12-13 16:56:56
,
所有人可见
,
阅读 41
//dfs怎么排除一种都没选的情况
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 14;
int n;
int a[N], b[N];
LL ans = 1e9;
void dfs(int u, LL A, int B) {
if (u >= n) {
if (A != 1 && B) ans = min(ans, abs(A - (LL)B));
return;
}
dfs(u + 1, A * a[u], B + b[u]);
dfs(u + 1, A, B);
}
int main() {
cin >> n;
for (int i = 0; i < n; i ++ )
cin >> a[i] >> b[i];
dfs(0, 1, 0);
cout << ans << endl;
return 0;
}