利用数据结构的算法解决这个遍历的难题的,怎么使用C语言程序实现

Problem Description
Long time ago , Kitty lived in a small village. The air was fresh and the scenery was very beautiful. The only thing that troubled her is the typhoon.

When the typhoon came, everything is terrible. It kept blowing and raining for a long time. And what made the situation worse was that all of Kitty's walls were made of wood.

One day, Kitty found that there was a crack in the wall. The shape of the crack is
a rectangle with the size of 1×L (in inch). Luckly Kitty got N blocks and a saw(锯子) from her neighbors.
The shape of the blocks were rectangle too, and the width of all blocks were 1 inch. So, with the help of saw, Kitty could cut down some of the blocks(of course she could use it directly without cutting) and put them in the crack, and the wall may be repaired perfectly, without any gap.

Now, Kitty knew the size of each blocks, and wanted to use as fewer as possible of the blocks to repair the wall, could you help her ?

Input
The problem contains many test cases, please process to the end of file( EOF ).
Each test case contains two lines.
In the first line, there are two integers L(0<L<1000000000) and N(0<=N<600) which
mentioned above.
In the second line, there are N positive integers. The ith integer Ai(0<Ai<1000000000 ) means that the ith block has the size of 1×Ai (in inch).

Output
For each test case , print an integer which represents the minimal number of blocks are needed.
If Kitty could not repair the wall, just print "impossible" instead.

Sample Input
5 3
3 2 1
5 2
2 1

Sample Output
2
impossible

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问

相似问题

3
java数据结构算法问题,几个数相加得到满足条件的最小和
1
C++ 数据结构 创建一个二叉树,广度优先遍历。为啥结果不正确?
1
数据结构如何遍历一个树上的边的算法
1
一个用C语言的数据结构算法的选择问题?谁知道
3
亲和串的问题怎么运用什么算法得以解决?数据结构
1
基于android利用getpixel遍历图编效率极其低下如何解决?
1
求一个比较困难的数据结构的算法难题的具体怎么实现
1
求大佬帮忙解决一下这道数据结构的题
1
一个关于C语言向量计算方面数据结构的算法的问题,采用C语言
1
一个收支平衡的计算的算法怎么使用数据结构和C语言的方式实现的呢?
1
最小费用流的问题,数据结构讨论下怎么实现最小费用的算法,采用C编程的办法
1
一个姓名的匹配算法的实现过程的分解,数据结构C语言解决这个问题的思路方式
1
DFS算法遍历图,返回上一层的问题。
1
数据结构上的一个线性表的冲突的解决,是不是用哈希算法怎么采用C语言的实现方式
0
一个数据结构有关连通图生成算法的一个问题,用C语言怎么解决这个问题?
0
区间整数遍历问题,子序列的遍历怎么使用C语言算法计算实现?
0
二叉搜索树在数据结构方面的综合运用,如何利用C语言编程解决这个算法?
0
一个采用C语言数据结构计算分割数组方面的算法难题的解答?
0
综合运用算法数据结构解决区间交的问题输出答案,C语言应用的问题