Sasha and Kolya decided to get drunk with Coke, again. This time they have k types of Coke. i-th type is characterised by its carbon dioxide concentration . Today, on the party in honour of Sergiy of Vancouver they decided to prepare a glass of Coke with carbon dioxide concentration . The drink should also be tasty, so the glass can contain only integer number of liters of each Coke type (some types can be not presented in the glass). Also, they want to minimize the total volume of Coke in the glass.

Carbon dioxide concentration is defined as the volume of carbone dioxide in the Coke divided by the total volume of Coke. When you mix two Cokes, the volume of carbon dioxide sums up, and the total volume of Coke sums up as well.

Help them, find the minimal natural number of liters needed to create a glass with carbon dioxide concentration . Assume that the friends have unlimited amount of each Coke type.

Input

The first line contains two integers n, k (0 ≤ n ≤ 1000, 1 ≤ k ≤ 106) — carbon dioxide concentration the friends want and the number of Coke types.

The second line contains k integers a1, a2, ..., ak (0 ≤ ai ≤ 1000) — carbon dioxide concentration of each type of Coke. Some Coke types can have same concentration.

Output

Print the minimal natural number of liter needed to prepare a glass with carbon dioxide concentration , or -1 if it is impossible.

Example

Input
400 4
100 300 450 500
Output
2
Input
50 2
100 25
Output
3

Note

In the first sample case, we can achieve concentration using one liter of Coke of types and : .

In the second case, we can achieve concentration using two liters of type and one liter of type: .

广搜,(a1+a2+...+am)/m == n;a1+a2+...+am = n * m;a1-n+a2-n+...am-n == 0;如此ai-n变为要存的值,节省了数组的空间。

#include <iostream>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
int visited[],ans[];
int n,k,s[],no;
int bfs()
{
memset(ans,-,sizeof(ans));
queue<int> q;
q.push();
ans[] = ;
int head,temp;
while(!q.empty())
{
head = q.front();
q.pop();
for(int i = ;i < no;i ++)
{
temp = head + s[i];
if(temp == )
{
ans[temp] = ans[head] + ;
return ans[temp];
}
else if(temp > && ans[temp] == -)
{
ans[temp] = ans[head] + ;
q.push(temp);
}
}
}
return -;
}
int main()
{
int d;
scanf("%d%d",&n,&k);
for(int i = ;i < k;i ++)
{
scanf("%d",&d);
if(visited[d] == )
{
visited[d] = ;
s[no ++] = d - n;
}
}
cout<<bfs();
return ;
}

The Great Mixing的更多相关文章

  1. Mixing Delphi and C++(相互调用)

    Mixing Delphi and C++ You have a TStringList and <algorithm>. What can you do? Quite a lot, ac ...

  2. Mixing a dll boost library with a static runtime is a really bad idea错误的解决

    作者:朱金灿 来源:http://blog.csdn.net/clever101 同事在使用boost库时遇到一个问题,在编译时出现一个错误:Mixing a dll boost library wi ...

  3. Codeforces 788C The Great Mixing

    The Great Mixing 化简一下公式后发现, 问题变成了, 取最少多少数能使其和为1, bitset优化一下背包就好啦. 题解中介绍了一种bfs的方法没, 感觉比较巧妙. #include& ...

  4. P1208 [USACO1.3]混合牛奶 Mixing Milk

    P1208 [USACO1.3]混合牛奶 Mixing Milk 题目描述 由于乳制品产业利润很低,所以降低原材料(牛奶)价格就变得十分重要.帮助Marry乳业找到最优的牛奶采购方案. Marry乳业 ...

  5. 洛谷——P1208 [USACO1.3]混合牛奶 Mixing Milk

    P1208 [USACO1.3]混合牛奶 Mixing Milk 题目描述 由于乳制品产业利润很低,所以降低原材料(牛奶)价格就变得十分重要.帮助Marry乳业找到最优的牛奶采购方案. Marry乳业 ...

  6. 洛谷 P1208 [USACO1.3]混合牛奶 Mixing Milk

    P1208 [USACO1.3]混合牛奶 Mixing Milk 题目描述 由于乳制品产业利润很低,所以降低原材料(牛奶)价格就变得十分重要.帮助Marry乳业找到最优的牛奶采购方案. Marry乳业 ...

  7. Mixing Milk 混合牛奶 USACO 贪心

    1009: 1.3.1 Mixing Milk 混合牛奶 时间限制: 1 Sec  内存限制: 128 MB提交: 9  解决: 9[提交] [状态] [讨论版] [命题人:外部导入] 题目描述 1. ...

  8. Educational Codeforces Round 88 (Rated for Div. 2) B、New Theatre Square C、Mixing Water

    题目链接:B.New Theatre Square 题意: 你要把所有"." 都变成"*",你可以有两个选择,第一种就是一次铺一个方块(1*1),第二种就是同一 ...

  9. 2019 GDUT Rating Contest I : Problem H. Mixing Milk

    题面: H. Mixing Milk Input file: standard input Output file: standard output Time limit: 1 second Memory ...

  10. Mixing ASP.NET and MVC routing

    Here is the solution I settled on. I installed the NuGet Microsoft.AspNet.FriendlyUrls package. Then ...

随机推荐

  1. eclipse(1)----ubuntu下的安装与配置

    eclipse的安装与配置 1.eclipse官网下载,最新版本eclipse-jee-oxygen-3-linux-gtk-x86_64.tar.gz 2.tar包存在~/Download/下,解压 ...

  2. linux中环境变量的用法

    Linux操作系统下三种配置环境变量的方法[转] 在linux下做开发首先就是需要配置环境变量,下面以配置java环境变量为例介绍三种配置环境变量的方法. 1.修改/etc/profile文件 如果你 ...

  3. 【HackerRank】Pairs

    题目链接:Pairs 完全就是Two Sum问题的变形!Two Sum问题是要求数组中和正好等于K的两个数,这个是求数组中两个数的差正好等于K的两个数.总结其实就是“骑驴找马”的问题:即当前遍历ar[ ...

  4. 在Java中调用Python代码

    极少数时候,我们会碰到类似这样的问题:与A同学合作写代码, A同学只会写Python,不熟悉Java ,而你只会写Java不擅长Python,并且发现难以用Java来重写对方的代码,这时,就不得不想方 ...

  5. iOS_KVC与KVO

    目 录: 一.KVC   二.KVO                                                                                   ...

  6. Linux与Android 多点触摸协议【转】

    本文转载自:http://blog.csdn.net/xubin341719/article/details/7833277 一.Linux与Android 多点触摸协议 为了使用功能强大的多点触控设 ...

  7. nginx面试要点

    首先列出一些面试题目包括nginx和redis的. 1..nginx 框架是怎样的 2. nginx负载均衡的算法怎么实现的,懵逼,说没看过  . nginx 的 upstream目前支持 4 种方式 ...

  8. 虚拟机开启Linux时出现“我以复制虚拟机”、“我已移动虚拟机”

    当出现标题的情况时,并且网络出现状况时,可以尝试一下解决办法 首先用ifconfig -a命令调出现在的网卡驱动的名称和HWaddr地址,然后再编辑/etc/sysconfig/networking/ ...

  9. 手把手教你安装SSL证书升级https

    是不是觉得别人网站前面的小绿锁很好看? 而且,Google官方也正式承认过https是影响搜索排名的一个因素,那么如何将自己的网站全面升级为https呢?今天的内容就介绍一下如何将部署在Nginx的W ...

  10. mysql在表的某一位置增加一列的命令

    如果想在一个已经建好的表中添加一列,可以用诸如: alter table t1 add column addr varchar(20) not null; 这条语句会向已有的表t1中加入一列addr, ...