[HDOJ5339] Untitled

Source: Internet
Author: User
Tags modulus

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

Give you n number b1...bn and a number A, let you take a to the b1...bn inside the number of modulo, the modulus after the value of 0 of the minimum number. You can repeat the value in B.

The first thing to be clear is that it doesn't make any sense to take a number to a smaller number and then take the modulus of a larger number. Therefore, it is meaningless to repeat the values, so the array B is sorted from large to small.

After the state is compressed, enumerate the numbers in B. You can also DFS out the results.

1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <algorithm>5#include <iostream>6#include <cmath>7#include <queue>8#include <map>9#include <stack>Ten#include <list> One#include <vector> A  - using namespacestd; -  the Const intMAXN =100010; - Const intINF =1<< -; - intN, A; - intB[MAXN]; +  -InlineintMinintAintb) { +     returnA < b?a:b; A } at intMain () { -     //freopen ("in", "R", stdin); -     intT; -scanf"%d", &T); -      while(t--) { -         intAns =INF; inscanf"%d%d", &n, &a); -          for(inti =0; I < n; i++) { toscanf"%d", &b[i]); +         } -Sort (b, b+n, greater<int>()); the         ints = (1<<n); *         intCNT; $          for(inti =1; I < S; i++) {Panax Notoginseng             intTMP =A; -CNT =0; the              for(intj =0; J < N; J + +) { +                 if(I & (1<<j)) { ATMP%=B[j]; thecnt++; +                 } -             } $             if(TMP = =0) { $Ans =min (ans, cnt); -             } -         } the         if(ans = =INF) { -printf"-1\n");Wuyi         } the         Else { -printf"%d\n", ans); Wu         } -     } About}

[HDOJ5339] Untitled

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.