题目传送门

 /*
DFS:从大到小取模,因为对比自己大的数取模没意义,可以剪枝。但是我从小到大也过了,可能没啥大数据
*/
/************************************************
Author :Running_Time
Created Time :2015-8-1 18:57:52
File Name :A.cpp
*************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; typedef long long ll;
const int MAXN = ;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + ;
int a[MAXN];
bool vis[MAXN];
int n, ans; bool cmp(int x, int y) {
return x > y;
} void DFS(int now, int step) {
for (int i=; i<=n; ++i) {
if (vis[i] || now < a[i]) continue;
if (now % a[i] == ) {
ans = min (ans, step + ); return ;
}
vis[i] = true; DFS (now % a[i], step + ); vis[i] = false;
}
} int main(void) { //HDOJ 5339 Untitled
int T; scanf ("%d", &T);
while (T--) {
int x; scanf ("%d%d", &n, &x);
for (int i=; i<=n; ++i) scanf ("%d", &a[i]);
sort (a+, a++n, cmp);
if (x < a[n]) {
puts ("-1"); continue;
}
memset (vis, false, sizeof (vis));
ans = INF; DFS (x, );
if (ans == INF) puts ("-1");
else printf ("%d\n", ans);
} return ;
}

DFS BestCoder Round #49 ($) 1001 Untitled的更多相关文章

  1. 贪心 BestCoder Round #39 1001 Delete

    题目传送门 /* 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 否则再在tot里减去多余的即为答案 用set容器也可以做,思路一样 */ # ...

  2. 暴力 BestCoder Round #41 1001 ZCC loves straight flush

    题目传送门 /* m数组记录出现的花色和数值,按照数值每5个搜索,看看有几个已满足,剩下 5 - cnt需要替换 ╰· */ #include <cstdio> #include < ...

  3. 暴力 BestCoder Round #46 1001 YJC tricks time

    题目传送门 /* 暴力:模拟枚举每一个时间的度数 详细解释:http://blog.csdn.net/enjoying_science/article/details/46759085 期末考结束第一 ...

  4. 字符串处理 BestCoder Round #43 1001 pog loves szh I

    题目传送门 /* 字符串处理:是一道水题,但是WA了3次,要注意是没有加'\0'的字符串不要用%s输出,否则在多组测试时输出多余的字符 */ #include <cstdio> #incl ...

  5. BestCoder Round #49

    呵呵哒,1001的dfs返回值写错,wa了两发就没分了,1002显然是PAM可是我没学过啊!!!压位暴力可不可以...看看范围貌似不行,弃疗...1003根本不会做,1004想了想lcc发现不可做,那 ...

  6. BestCoder Round #75 1001 - King's Cake

    Problem Description It is the king's birthday before the military parade . The ministers prepared a ...

  7. BestCoder Round #92 1001 Skip the Class —— 字典树 or map容器

    题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=748&pid=1001 题解: 1.trie树 关 ...

  8. BestCoder Round #91 1001 Lotus and Characters

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6011 题意: Lotus有nn种字母,给出每种字母的价值以及每种字母的个数限制,她想构造一个任意长度的 ...

  9. BestCoder Round #61 1001 Numbers

    Problem Description There are n numbers A1,A2....An{A}_{1},{A}_{2}....{A}_{n}A​1​​,A​2​​....A​n​​,yo ...

随机推荐

  1. Servlet的调试

    以下内容引用自http://wiki.jikexueyuan.com/project/servlet/debugging.html: 测试/调试Servlet始终是困难的.Servlets往往涉及大量 ...

  2. SDUTOJ 2476Period

    #include<iostream> #include<string.h> #include<stdio.h> #define N 1000010 using na ...

  3. Codeforces 455B A Lot of Games 字典树上博弈

    题目链接:点击打开链接 题意: 给定n个字符串,k局游戏 对于每局游戏,2个玩家轮流给一个空串加入一个小写字母使得加完后的字符串不是n个字符串的前缀. 输家下一轮先手 问是先手必胜还是后手必胜 思路: ...

  4. 组件的使用(四)DatePickerDialog和TimePickerDialog的使用

    这两个组件的使用都须要获得当前日期或时间.实现方法是获得一个Calender实例(调用getInstance()实例化) DatePickerDialog的使用 Calendar calendar=C ...

  5. 【手势交互】8. Nimble Sense

    早在2012.2013年度,手势识别领域就发生了几起重要的行业并购.比方英特尔对Omek的收购,谷歌对Flutter的收购.而苹果公司更是以3.45亿美金得高价收购了之前为微软Kinect提供技术支持 ...

  6. Flex 页面启动事件

    事件启动顺序 容器Preinitialize=>子组件preinitialize=>子组件initialize=>childAdd=>initialize =>子组件cr ...

  7. [办公应用]如何设置IE打印时的默认页边距,并设置纸张为横向(会计票据打印)

    最近一个做会计的同事询问,如何将IE打印时的默认页边距更改,并且每次都要是横向的纸张. 这是因为她已经测试好纸张的大小,并据此调整好了页边距.可惜的是下一次打印时,又要重新调整一遍. 经过研究,方法如 ...

  8. 【Noip模拟By yxj】

    1.randomDescription 给定4个参数A0,N,c,p,你需要按下式构造A1~AN: A[i]=(A[i-1]2+c)mod p 之后,你需要求出A1~AN中,第K大的数值.Input ...

  9. 阿里电话面试问题----100万个URL怎样找到出现频率最高的前100个?

    内推阿里电话面试中面试官给我出的一个题: 我想的头一个解决方式.就是放到stl 的map里面对出现的频率作为pair的第二个字段进行排序.之后依照排序结果返回: 以下口说无凭,show your co ...

  10. Bootstrap popover源码分析

    /* ======================================================================== * Bootstrap: popover.js ...