hdu5339Untitled
2015-08-10 09:22
267 查看
看题目点我啊~
问一个数被至少多少个数取模后得0 注意得先排序啊啊啊啊啊啊啊啊
问一个数被至少多少个数取模后得0 注意得先排序啊啊啊啊啊啊啊啊
#include <iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int t,b[30],n,minn; int MIN(int a,int b) { return a>b?b:a; } bool cmp(int a,int b) { return a>b; } void dfs(int mod,int pos,int time) { if(mod==0) { minn=MIN(minn,time); return; } if(pos==n) return; dfs(mod%b[pos+1],pos+1,time+1); dfs(mod,pos+1,time); } int main() { //freopen("cin.txt","r",stdin); while(~scanf("%d",&t)) { int a; while(t--) { scanf("%d%d",&n,&a); for(int i=1;i<=n;i++) scanf("%d",&b[i]); sort(b+1,b+1+n,cmp); minn=50; dfs(a,0,0); if(minn==50) printf("-1\n"); else printf("%d\n",minn); } } return 0; }
相关文章推荐
- jQuery图片上传前先在本地预览
- Android官方数据绑定框架DataBinding(一)
- JAVA 基本数据类型长度
- Run
- 深入学习C语言中的函数指针和左右法则
- 信号包络
- Spring HTTP Invoker使用介绍
- 计蒜客 难题题库 032 罗马数字
- 8月书讯:喜悦翩然而至
- 安卓安装过程
- SAP*和DDIC用户被锁分析与解决方案
- XXXX
- My debug:error C2275: “XXX”: 将此类型用作表达式非法
- atomthread 在 iar-stm8中编译错误
- 如何将动态URL静态化!
- Remove Duplicates from Sorted List II
- 计蒜客 难题题库 031 无脑博士的试管们
- 计蒜客 难题题库 030 合法分数的组合
- CSS3实现的一批hover特效
- wpf 代码设置图片路径(后台和xamll)