Input
The first line of the input contains a single integer T (1 <= T <= 20), the number of test cases. Then T cases follow. The first line of each case contains N, and the second line contains N integers giving the time for each people to cross the river. Each case is preceded by a blank line. There won t be more than 1000 people and nobody takes more than 100 seconds to cross.
Output
For each test case, print a line containing the total number of seconds required for all the N people to cross the river.
Sample Input
1
4
1 2 5 10
Sample Output
17
Dijkstra算法求最短路徑(C#版) using System
using System.Collections
using System.Text
namespace Greedy
{
class Marx
{
private int[] distance
private int row
private ArrayList ways = new ArrayList()
public Marx(int n,params int[] d)
{
this.row = n
distance = new int[row * row]
for (int i = 0 i < row * row i++)
{
this.distance[i] = d[i]
編寫具有如下函數(shù)原型的遞歸與非遞歸兩種函數(shù)equ,負(fù)責(zé)判斷數(shù)組a與b的前n個元素值是否按下標(biāo)對應(yīng)完全相同,是則返回true,否則返回false。并編制主函數(shù)對它們進(jìn)行調(diào)用,以驗證其正確性。
bool equ(int a[], int b[], int n)
提示:遞歸函數(shù)中可按如下方式來分解并處理問題,先判斷最后一個元素是否相同,不同則返false;相同則看n是否等于1,是則返回true,否則進(jìn)行遞歸調(diào)用(傳去實參a、b與 n-1,去判斷前n-1個元素的相等性),并返回遞歸調(diào)用的結(jié)果(與前n-1個元素的是否相等性相同)。