。。
Untitled
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 301 Accepted Submission(s): 156
For each testcase, there are two lines:
1. The first line contains two integers n and a ( 1≤n≤20,1≤a≤106 ).
2. The second line contains n integers b1,…,bn ( ?1≤i≤n,1≤bi≤106 ).
2 2 9 2 7 2 9 6 7
2 -1
/* ***********************************************
Author :
Created Time :2015/8/1 18:42:07
File Name :2.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 1<<30
#define maxn 100+10
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
bool cmp(int a,int b){
return a>b;
}
int a[maxn];
int x,y;
int n;
int ans;
int mark;
void dfs(int x,int cnt){
if(cnt>n)return ;
if(x==0) {
mark=1;
ans=min(ans,cnt);return ;
}
for(int i=1;i<=n;i++){
if(x<a[i])continue;//剪枝
y=x%a[i];
dfs(y,cnt+1);
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int t;
cin>>t;
while(t--){
cle(a);
scanf("%d %d",&n,&x);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
ans=INF;
mark=0;
dfs(x,0);
if(mark)printf("%d\n",ans);
else puts("-1");
}
return 0;
}