#include<bits/stdc++.h>
using namespace std;
const int N = 50;
const int INF = 0x3f3f3f3f;
int n,ans = INF;
int acid[N],sweet[N];
void DFS(int i,int x,int y){
if(i > n){
if(x == 1 && y == 0)return;
ans = min(ans,abs(x - y));
return;
}
DFS(i + 1,x * acid[i],y + sweet[i]);
DFS(i + 1,x,y);
}
int main(){
cin>>n;
for(int i = 1;i <= n;i++)cin>>acid[i]>>sweet[i];
DFS(1,1,0);
cout<<ans<<endl;
}
P2392 kkksc03考前临时抱佛脚(洛谷 数据型DFS)
最新推荐文章于 2022-12-03 16:09:35 发布