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