分类的分循环的问题算法,采用C程序语言的设计的思路是什么

Problem Description
Roy has just moved into a new apartment. Well, actually the apartment itself is not very new, even dating back to the days before people had electricity in their houses. Because of this, Roy's apartment has only one single wall outlet, so Roy can only power one of his electrical appliances at a time.
Roy likes to watch TV as he works on his computer, and to listen to his HiFi system (on high volume) while he vacuums, so using just the single outlet is not an option. Actually, he wants to have all his appliances connected to a powered outlet, all the time. The answer, of course, is power strips, and Roy has some old ones that he used in his old apartment. However, that apartment had many more wall outlets, so he is not sure whether his power strips will provide him with enough outlets now.
Your task is to help Roy compute how many appliances he can provide with electricity, given a set of power strips. Note that without any power strips, Roy can power one single appliance through the wall outlet. Also, remember that a power strip has to be powered itself to be of any use.

Input
Input will start with a single integer 1 <= N <= 20, indicating the number of test cases to follow. Then follow N lines, each describing a test case. Each test case starts with an integer 1 <= K <= 10, indicating the number of power strips in the test case. Then follow, on the same line, K integers separated by single spaces, O1 O2 . . . OK, where 2 <= Oi <= 10, indicating the number of outlets in each power strip.

Output
Output one line per test case, with the maximum number of appliances that can be powered.

Sample Input
3
3 2 3 4
10 4 4 4 4 4 4 4 4 4 4
4 10 10 10 10

Sample Output
7
31
37

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

相似问题

2
一个c语言的算法循环问题
1
数据结构上的一个线性表的冲突的解决,是不是用哈希算法怎么采用C语言的实现方式
0
顺序重排的算法的问题,输出可行性判断,采用C语言的算法思路的实现
0
矩阵 的Hadamard积的数据结构的算法,采用C语言编程技术如何实现的思路
0
组合问题的难度的控制算法,采用C语言编程的实现的方式
0
字母字面值和数字的组合排序算法问题,采用C语言编程思路的实现方式
1
速度和距离关系问题的一个推断算法,采用C编程语言技术实现
1
素数的队列的计算问题的算法,采用C语言的编程计算实现它
0
纸牌牌面正反的判断问题的算法,怎么采用C语言程序设计的办法来实现的
0
金币在篮子当中的分装的问题的算法,采用C语言程序的编写过程实现
0
连通图数据结构上面的一个路径的搜索的算法问题,采用C语言的程序的设计的办法
0
可编码的数据的重新分配N的算法,采用C语言的程序设计语言的编写
0
拥有N个定点的无向图的一个算法的问题,采用C语言的程序设计思路的办法来怎么解决的
0
丢石头的游戏的一个算法的问题如何采用C语言的程序的编程的方法来实现的呢
0
计算最大质因数的一个算法的问题,怎么利用C语言的程序设计的思路来解决
0
寻找两条最接近的路径的算法问题,采用C语言程序设计的办法如何解决的呢?
0
数字连乘的一个算法问题,循环的计算用C语言的程序设计的办法
0
时间推演算法问题的一个思路用的数据结构,怎么采用C语言的程序设计方式来实现
0
MAP数据结构在搜寻算法的运用,采用C语言的程序的设计的思路解决
0
循环队列的旋转的一个算法问题怎么利用C语言的程序的编写来求解的