0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:31:59 +00:00

P2036 [COCI2008-2009#2] PERKET

R52228829
This commit is contained in:
Baoshuo Ren 2021-06-30 21:48:54 +08:00 committed by Baoshuo Ren
parent c0cc097c32
commit 7d450ae7c6
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -0,0 +1,28 @@
#include <bits/stdc++.h>
using namespace std;
struct {
int s, b;
} a[15];
int n, ans = 0x3f3f3f3f;
void dfs(int now, int s, int b) {
if (now > n) {
if (s == 1 && b == 0) return;
ans = min(abs(s - b), ans);
return;
}
dfs(now + 1, s * a[now].s, b + a[now].b);
dfs(now + 1, s, b);
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].s >> a[i].b;
}
dfs(1, 1, 0);
cout << ans << endl;
return 0;
}