题目传送门

 /*
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. 【NOIP2017练习】论战大原题(并查集)

    题意:给定一个n个点m条边的无向图.定义一条路径的长度为路径上最小边的权值. 定义dist(i,j)为起点为i,终点为j的长度最长的路径的长度.求出第k大的dist(i,j)(i<j). 对于所 ...

  2. struts2开发action 的三种方法以及通配符、路径匹配原则、常量

    struts2开发action 的三种方法 1.继承ActionSupport public class UserAction extends ActionSupport { // Action中业务 ...

  3. Java电商项目-5.内容管理cms系统

    目录 实现加载内容分类树功能 实现内容分类动态添加 删除内容分类节点 实现内容分类节点的分页显示 实现广告内容的添加 实现广告内容删除 实现广告内容编辑 到Github获取源码请点击此处 实现加载内容 ...

  4. Android 4.4环境搭建——配置AVD模拟器

    AVD(Android Virtual Device)即Android模拟器,它是Android官方提供的一个能够执行Android程序的虚拟机,在执行Android程序之前,首先须要创建AVD模拟器 ...

  5. SDUST 2844-Mineral Water(数学)

    Mineral Water nid=24#time" title="C.C++.go.haskell.lua.pascal Time Limit1000ms Memory Limi ...

  6. 常用Lunix命令

    计算机 1.硬件系统 输入单元.输出单元.算术逻辑单元.控制单元.记忆单元 中央处理单元:CPU(算术逻辑单元.控制单元) 电源.主板.CPU.内存(RAM).硬盘.(声卡.显卡.网卡)(集成在主板上 ...

  7. Codeforces Round #323 (Div. 2) D. Once Again... 暴力+最长非递减子序列

                                                                                  D. Once Again... You a ...

  8. 【codevs2183】匹配字符串

    KMP裸题 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring ...

  9. 【bzoj2743】[HEOI2012]采花

    树状数组 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring& ...

  10. 局部优化与整体效果 新增时间>节省时间 权衡利弊

    原代码 from selenium import webdriverimport requests,timeurl_l=[]with open('DISTINCT_url.txt', 'r', enc ...