标签:
1 #include<cstdio> 2 #include<algorithm> 3 using namespace std; 4 5 int ans,m,n; 6 int b[21]; 7 8 bool cmp(int a,int b) 9 { 10 return a>b; 11 } 12 13 void dfs(int total,int cur,int num) 14 { 15 if(total==0) 16 { 17 ans=min(ans,num); 18 return; 19 } 20 if(cur==m) 21 return; 22 dfs(total%b[cur],cur+1,num+1); 23 dfs(total,cur+1,num); 24 } 25 26 int main() 27 { 28 //freopen("in.txt","r",stdin); 29 int i,t; 30 scanf("%d",&t); 31 while(t--) 32 { 33 ans=21; 34 scanf("%d%d",&m,&n); 35 for(i=0;i<m;i++) 36 scanf("%d",&b[i]); 37 sort(b,b+m,cmp); 38 dfs(n,0,0); 39 if(ans==21) 40 printf("-1\n"); 41 else 42 printf("%d\n",ans); 43 } 44 return 0; 45 }
标签:
原文地址:http://www.cnblogs.com/homura/p/4711105.html