算法训练-Sticks


title: 算法训练 Sticks
categories:

  • ACM
  • dfs
    tags:
  • 高级dfs
    date: 2020-03-18 19:08:24

还记得dfs的入门题吗?输入n个数和一个结果m,问这n个数能不能组合成m。这个题就是在能凑成m的基础上再从头开始搜索,注意不能运行多次dfs,而是要递归调用,因为不能确定找到一个m就是其中的一个m,有可能不合法。dfs的代码风格有两种,一种是正序,一种是倒序

问题

试题 算法训练 Sticks

提交此题

资源限制

时间限制:1.0s 内存限制:999.4MB

Sticks

Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 113547 Accepted: 26078

问题描述

George took sticks of the same length and cut them randomly until all parts became at most 50 units long. Now he wants to return sticks to the original state, but he forgot how many sticks he had originally and how long they were originally. Please help him and design a program which computes the smallest possible original length of those sticks. All lengths expressed in units are integers greater than zero.

输入格式

The input contains blocks of 2 lines. The first line contains the number of sticks parts after cutting, there are at most 64 sticks. The second line contains the lengths of those parts separated by the space. The last line of the file contains zero.

输出格式

The output should contains the smallest possible length of original sticks, one per line.

样例输入

9
5 2 1 5 2 1 5 2 1
4
1 2 3 4
0

样例输出

5
6

题目大意

多个测试用例,第一行输入木棒的个数n,下一行输入n个数代表不同木棒的长度,这些木棒可以组成m个长度为k的长木棒,输出k的最小值

发布了43 篇原创文章 · 获赞 1 · 访问量 909

猜你喜欢

转载自blog.csdn.net/qq_43985303/article/details/105150156
今日推荐