题目链接:https://www.luogu.com.cn/problem/P2036
这道题我个人认为是递归而并非搜索。
#include <bits/stdc++.h>
#define MAXN 450
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
struct Node
{int suan;int tian;
}node[25];int n;
int mini=0xffff;
void f(long long s,long long t,int k)
{if(k>n){if(s==1&&t==0){return ;}mini=min(mini,(int)abs(s-t));return ;}f(s*node[k].suan,t+node[k].tian,k+1);f(s,t,k+1);}int main(int argc, char** argv)
{cin>>n;for(int i=1; i<=n; i++){cin>>node[i].suan>>node[i].tian;}f(1,0,1);cout<<mini<<endl;return 0;
}/**/