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. 每天一个Linux命令(56)yum命令

          用于添加/删除/更新RPM包,自动解决包的依赖问题以及系统更新升级.     (1)用法:     用法:  yum  [参数] [软件名]     (2)功能:     功能:  yum ...

  2. 关于pycharm中的requirements.txt文件

    作用:记录所有所依赖的第三方模块,方便迁移到不同的环境中后,防止缺少模块,或因为所依赖的第三方模块版本不同引起不必要的问题 生成命令:pip freeze > requirements.txt ...

  3. Windos Server 2008 Backup 安装使用

    系统环境:Windos 2008 R2 x64 实施方案:备份系统 完全备份,每周备份一次,备份文件映射到文件服务器. 安装备份工具 使用Windos Sserver Backup 做备份 设置每周备 ...

  4. NSFetchedResultController与UITableView

    1 #import "AppDelegate.h" #import "Book.h" @interface AppDelegate () @end @imple ...

  5. Vue.js学习笔记 第二篇 样式绑定

    Class绑定的对象语法 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

  6. Kubernetes Horizontal Pod Autoscaler

    非常牛逼的技术,目前最新的版本支持众多的Feature HPA功能需要Heapster收集的CPU.内存等数据作为支撑 配置示例: apiVersion: autoscaling/v2beta1 ki ...

  7. linux下ipython的安装

    第一种:ipython源码安装ipython的源码下载页面为:https://pypi.python.org/pypi/ipython 或者是到git页面下载:https://github.com/i ...

  8. iptable防火墙面试题

    第1章 (一)基础口试题 1.1 详述 iptales 工作流程以及规则过滤顺序? 1.防火墙是一层层过滤的.实际是按照配置规则的顺序从上到下,从前到后进行过滤的. 2.如果匹配上了规则,即明确表明是 ...

  9. struts2发送ajax的几个问题(不使用struts2-json-plugin的情况下)

    采用原始方式发送ajax到action时,会遇到get,post的不同,原因是ContentType的问题,ContentType必须是text/html,struts获取到的inputStream才 ...

  10. 剑指Offer——重建二叉树2

    Question 输入某二叉树的后序遍历和中序遍历的结果,请重建出该二叉树.假设输入的后序遍历和中序遍历的结果中都不含重复的数字.例如输入后序遍历序列{1, 3, 4, 2}和中序遍历序列{1, 2, ...