Bestcoder #49 Untitled HDU 5339

Source: Internet
Author: User

Bestcoder #49 Untitled HDU 5339


Title: http://acm.hdu.edu.cn/showproblem.php?pid=5339


The subject uses deep search, small data volume, first do sort processing (descending), and then deep search, to prune, than the number of k is not necessary to search back, directly cut off.


#include <iostream> #include <algorithm> #include <cstdio>using namespace std;const int INF = 200;int        Arr[20+5] = {};void dfs (int t, int n, int k, int &ans) {if (k==0) {ans = min (ans, t);    Return        } if (T < n) {if (k%arr[t] = = 0) {ans = min (ans, t+1);            } else if (K > Arr[t])//To do pruning, greater than k does not need to be processed backwards {DFS (t+1, N, K%arr[t], ans);        DFS (t+1, n, K, ans); }}}inline BOOL CMP (const int &AMP;A, const int &b) {return a > B;}    int main (void) {//freopen ("In.txt", "R", stdin);    int t = 0;    cin>>t;        while (t--) {int n, K;        cin>>n>>k;      int zero = 0;        If the input data contains a factor of k, then the result must be 1 int v = 0;        int j = 0;            for (int i=0; i<n; ++i) {scanf ("%d", &v);            if (K%v = = 0) zero = 1;        if (v < k) arr[j++] = v; } IF (zero = = 1) {printf ("1\n");        Continue      } sort (arr, arr+j, CMP);        ORDER by DESC//printf ("%d\n", arr[0]);        int ans = INF;        DFS (0, J, K, ans);    printf ("%d\n", Ans==inf -1:ans); } return 0;}




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. Http://blog.csdn.net/core__code

Bestcoder #49 Untitled HDU 5339

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.