题目传送门

 /*
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. 洛谷P2888 [USACO07NOV]牛栏Cow Hurdles

    题目描述 Farmer John wants the cows to prepare for the county jumping competition, so Bessie and the gan ...

  2. Python基础之 一列表

    列表模块:listlen(list):列表元素个数max(list):列表元素最大值min(list):列表元素最小值list(seq):将元组转为列表list.append(obj):列表末尾添加新 ...

  3. webpack—入门

    点击进入webpack官网.,开始教程时,建议先学习ES6语法,也请先观看本篇Windows符号介绍文章,当所有webpack内容学习完后,会有一个专门的介绍 webpack四个核心概念(从官网入门— ...

  4. 小贝_mysql 存储过程

    存储过程 简要: 1.什么是存储过程 2.使用存储过程 一.存储过程 概念类似于函数,就是把一段代码封装起来.当要行这段代码的时候,能够通过调用该存储过程来实现.在封装的语句体里面.能够用if/els ...

  5. 使用Scroller制作滑块开关ToggleButton

    Scroller这个类在自己定义view中使用的还算是非常频繁的,和它名字一样.我们通常是在控制滑动的时候使用Scroller,以便让view滑动起来不那么生硬.在官方的解释上,Scroller是一个 ...

  6. python开发【第4篇】【进程、线程、协程】

    一.进程与线程概述: 进程,是并发执行的程序在执行过程中分配和管理资源的基本单位,每一个进程都有一个自己的地址空 间. 线程,是进程的一部分,一个没有线程的进程可以被看作是单线程的.线程有时又被称为轻 ...

  7. kernel devel 安装与卸载

    1.查看系统内核 uname -r 2.查看已安装kernel-devel uname -a ; rpm -qa kernel\* | sort 3.下载对应的rpm wget xxx/kernel- ...

  8. 修改版Putty,可保持密码

    修改版Putty,可保持密码: http://files.cnblogs.com/findumars/putty_v6.0.rar 转自: http://unmi.cc/putty-auto-logi ...

  9. fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt

    project->xx Properties->Manifest->Input and Output->Embed Manifest将yes修改为no

  10. Notification操作大全

    目录 一:普通的Notification Notification 的基本操作 给 Notification 设置 Action 更新 Notification 取消 Notification 设置 ...