HDU 4283 You Are the One 37th ACM/ICPC Tianjin division Network Competition 1006 question (DP)

Source: Internet
Author: User
You are the one

Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 402 accepted submission (s): 221

Problem description the TV shows such as you are the one has been very popular. in order to meet the need of boys who are still single, tjut hold the show itself. the show is hold in the small hall, so it attract a lot of boys and girls. now there are n boys enrolling in. at the beginning, the N boys stand in a row and go to the stage one by one. however, the director suddenly knows that very boy H As a value of diaosi D, if the boy is k-th one go to the stage, the unhappiness of him will be (k-1) * D, because he has to wait for (k-1) people. luckily, there is a dark room in the small hall, so the director can put the boy into the dark room temporarily and let the boys behind his go to stage before him. for the dark room is very narrow, the boy who first get into dark room has to leave last. t He director wants to change the order of boys by the dark room, so the summary of unhappiness will be least. Can you help him?

 

Input the first line contains a single integer t, the number of test cases. For each case, the first line is n (0 <n <= 100)
The next N line are n integer D1-Dn means the value of diaosi of boys (0 <= di <= 100)

 

Output for each test case, output the least summary of unhappiness.

 

Sample input2 5 1 2 3 4 5 5 4 3 2 2

 

Sample outputcase #1: 20 case #2: 24

 

Source2012 ACM/ICPC Asia Regional Tianjin online

 

Recommendliuyiding Such a simple DP, the game did not come up... Alas... I still need to practice more DP.
 /* HDU 4283dp  */  # Include <Stdio. h> # Include <Iostream> # Include <Algorithm> # Include < String . H> Using   Namespace  STD;  Const   Int Maxn = 120  ; Const   Int INF = 0x3f3f3f  ;  Int  Num [maxn];  Int  Sum [maxn];  Int DP [maxn] [maxn]; //  DP [I] [J] indicates the minimum value generated by the sequence from number I to number J.  Int  Main (){  Int  T;  Int N;  Int Icase = 0  ; Scanf (  "  % D  " ,& T );  While (T -- ) {Icase ++ ; Scanf (  "  % D  " ,& N); sum [ 0 ] = 0  ;  For ( Int I = 1 ; I <= N; I ++ ) {Scanf (  "  % D  " ,& Num [I]); sum [I] = Sum [I- 1 ] + Num [I];}  For (Int I = 1 ; I <= N; I ++ )  For ( Int J = I; j <= N; j ++ ) DP [I] [J] = INF;  For ( Int I = 1 ; I <= N; I ++ ) DP [I] [I] = 0  ;  For ( Int Len = 1 ; Len <n; Len ++ )  For ( Int I = 1 ; I + Len <= N; I ++ ){  Int J = I + Len; DP [I] [J] = Min (DP [I] [J], DP [I + 1 ] [J] + sum [J]- Sum [I]);  For ( Int K = I + 1 ; K <= J; k ++ ) DP [I] [J] = Min (DP [I] [J], DP [I + 1 ] [K] + num [I] * (k-I) + dp [K + 1 ] [J] + (sum [J]-sum [k]) * (k-I + 1  );} Printf (  "  Case # % d: % d \ n  " , Icase, DP [ 1  ] [N]);}  Return   0  ;} 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.