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. $Java正则表达式基础整理

    (一)正则表达式及语法简介 String类使用正则表达式的几个方法: 正则表达式支持的合法字符: 特殊字符: 预定义字符: 方括号表达式: 圆括号表达式:用于将多个表达式组成一个子表达式,可以使用或运 ...

  2. 吐槽 坑爹的MySQL安装路径选择

    一般再windows下面安装MySQL我们都会选择msi安装模式,然而安装最新版的MySQL(mysql-installer-community-5.7.11.0.msi 下载地址)发现MySQL默认 ...

  3. 【Head First Servlets and JSP】笔记16:JSP隐式对象(内置对象)的映射关系

    接笔记15. 1.不管是JSP中的<%%>还是<%\=%>最终都将处于servlet的方法体中,那么有没有一种元素可以声明成类的成员呢? ——答案是有,而且非常非常简单,这个元 ...

  4. SpringBoot Mybatis 入门

    Mybatis for Java API官方文档:http://www.mybatis.org/mybatis-3/zh/java-api.html Mybatis语法介绍 @Select 查询,所有 ...

  5. Mybatis入门2-动态代理实现CRUD

    MyBatis动态代理生成DAO的步骤: 1) 编写数据管理的接口XxxMapper 2) 编写该接口对应的Mapper.xml a) namespace必须与Mapper接口全名一致 b) stat ...

  6. Centos6.5安装php5.6.7

    1. 下载 官网:http://php.net/downloads.php wget http://cn2.php.net/get/php-5.6.7.tar.gz/from/this/mirror ...

  7. dedecms 织梦列表页标题增加显示页数

    判断是否为第一页,为第一页则不显示页数的代码: {dede:pagelist listsize='0' listitem='pageno' function='html2text(@me)' runp ...

  8. MAC 系列 之XCode7.1 + HBuilder MUI 离线打包 ipa 上次application leader 问题:ERROR ITMS - 90534

    解决方法:这个原因 网上说法是 beta 测试版本:不过的确是beta版本(7.3 beta)打包的,所以我有下载了一个正式版本 7.1版本. 再次进行测试打包!

  9. C# XML对象序列化、反序列化 - PEPE YU

    http://www.tuicool.com/articles/IjE7ban http://www.cnblogs.com/johnsmith/archive/2012/12/03/2799795. ...

  10. 保护SSH的三把锁

    ///////////////////////////////写在前面//////////////////////////////////////原帖地址:http://www.ibm.com/dev ...