DCP-534: Sanvi and Card Game 2 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 some cards. In her Card game there may be maximum of **13** and there will be at least two Cards. Each card has a positive integer written on it . At the begin of game, Saanvi would like to make some 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 out in how many ways she can shuffle to get this maximum summation. Input: ------ Input starts with an integer **T (1 &le; T &le; 100)**, denoting the number of test cases. Each case contains an integer **N (2 &le; 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 **positive integer upto 10<sup>12</sup>**. Output: ------- For each case of input, output the number of ways of she can shuffle to get the maximum summation. Sample Input ------------ 3 2 1 5 3 1 3 5 3 8 8 8 Sample Output ------------- 2 4 6 For second Test case , 4 possible shuffle to get the maximum summation (which is 6) is [1,5,3] , [3,5,1] , [3,1,5] , [5,1,3]


Problem Setter:

Md. Tariqul Islam

Please login to submit solution to this problem.

Problem Limits

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

Problem Stats

16/67

Solve/Submission

Ranking

# User Language Timing
01 ovis96 Cpp14 0.85s
02 PKP_Junior Cpp 0.90s
03 shefin Cpp 0.90s
04 kzvd4729 Cpp14 0.93s
05 imranziad Cpp 1.00s
06 Hasinur_ Cpp14 1.22s
07 Morass Cpp14 1.45s
08 mahbubcseju Cpp 1.70s
09 Nirjhor Cpp 1.74s
10 tariqiitju Cpp 1.77s
11 Nobel Cpp 2.02s
12 Zeronfinity Cpp 2.08s
Feedback

Your feedback is our precious!



Or call +88 02 9853138 for support