# DCP-305: Sanvi and Card Game Back to All Problems

Medium Divide and Conquer > Dynamic Programming

**Sanvi** is a very cute girl. She likes to play Card game very much. One day, she came with the cards with some value written in the back side of every cards. In her Card game there may be maximum of **13** and there will be at least two Cards. The Cards numbered from 1 to maximum numeric digit of available total cards. At the begin of game, Saanvi would like to make the shuffle of cards on her hand as much time as she likes so that the summation of absolute difference of every two consecutive cards from top to bottom on her hand will be maximum. Your task is to help her to find this maximum summation. Input: ------ Input starts with an integer **T (T<=1<=100)**, denoting the number of test cases. Each case contains an integer **N (2 ≤ N ≤ 13)** denoting the number of Cards in current game. The next line will contain N integers separated by spaces, **ith** of which denotes the value written on **Card number- i** . Each of these integers will be a **non negative integer upto 1000000000000**. Output: ------- For each case of input, output the maximum summation she may get after doing shuffle of cards as many times as she desires. Sample Input ------------ 2 2 1 5 3 1 3 5 Sample Output ------------- 4 6

### Problem Limits

 Language Time Limit (seconds) C 1.00 C++ 1.00 C++14 1.00 C# 1.00 Go 1.00 Java 1.00 JavaScript 1.00 Objective-C 1.00 Perl 1.00 PHP 1.00 Python 1.00 Python3 1.00 Ruby 1.00 VB.Net 1.00

# 27/220

Solve/Submission

### Ranking

# User Language Timing
01 Morass Cpp14 0.00s
02 rayhan50001 Cpp 0.01s
03 onucsecu Cpp14 0.01s
04 tariqiitju Cpp 0.05s
05 feodorv Cpp14 0.09s
06 _The_Beast_ Cpp 0.18s
07 AlirezaNa Cpp14 0.25s
08 Robbinb1993 Cpp 0.29s
09 rajdipsaha Cpp14 0.33s
10 seyedssz Cpp14 0.37s
11 Pure_Protea Cpp14 0.41s
12 imAnik Cpp14 0.45s
13 njrafi Cpp14 0.63s
14 Al_Pacino Cpp14 0.66s
15 SakibAlamin Cpp 0.90s
Feedback