아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Merge the Books

시간 제한1.5초메모리 제한1024 MB

요약
책 더미 n개를 두 개씩 합치는데, 합칠 때마다 올리는 더미의 무게와 두 더미의 마모값을 더한 에너지가 들고 새 마모값은 둘 중 큰 값의 두 배에 1을 더한 값이 된다. 총 에너지의 최솟값을 구한다.
난이도

보통10점 중 6점

유형
동적 계획법, 그리디
정답자
아직 제출이 없습니다

문제

Little C has nn books, each with a weight, and he decides to merge them into a pile.

Each time when Little C merges, he can put one pile of books on top of another to merge them into one pile. If Little C puts the ii-th pile of books on top of the jj-th pile of books, the energy Little C needs to consume is the weight of the ii-th pile of books plus the wear value of the two piles of books.

Initially, each book is in its own pile and the wear values are all 00. Whenever Little C merges two piles of books, the wear value of the new pile of books formed is twice the larger of the wear values of the two piles of books before merging, plus one. The weight of the new pile of books is the sum of the weights of the two piles of books before merging.

Your task is to design a merging order to minimize the total energy consumption of Little C and output the minimum total energy consumption.

입력

This problem has multiple test data sets.

The first line of the input contains an integers tt, which represents the number of test data sets.

Then, each set of test data is given as input in order. For each set of test data:

The first line of input contains a positive intege nn, which represents the number of books.

The second line of input contains nn positive integers w_1,w_2,…,w_nw\_1,w\_2,\dots,w\_n, where w_iw\_i represents the weight of the ii-th book.

출력

For each set of test data, output a line containing an integer, representing the minimum total energy consumption.

제한

For all test data, it is guaranteed that: 1≤t≤10,1≤n≤100,1≤w_i≤1091 \leq t\leq 10,1\leq n\leq 100,1\leq w\_i\leq 10^9.

예제1

  1. 예제 1

    입력
    1
    4
    1 1 1 1
    
    예상 출력
    6