HDU 4277 usaco orz 37th ACM/ICPC Changchun division Network Competition 1011 questions (Search)

Source: Internet
Author: User
Usaco orz

Time Limit: 5000/1500 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 1099 accepted submission (s): 398

Problem descriptionlike everyone, cows enjoy variety. Their current fancy is new shapes for pastures. The old rectangular shapes are out of favor; new geometries are the favorite.
I. m. hei, the lead cow pasture regular ect, is in charge of creating a triangular pasture surrounded by nice white fence rails. she is supplied with N fence segments and must arrange them into a triangular pasture. ms. hei must use all the rails to create three sides of non-zero length. calculating the number of different kinds of pastures, she can build that enclosed with all fence segments.
Two pastures look different if at least one side of both pastures has different lengths, and each pasture shocould not be degeneration.

 

Inputthe first line is an integer T (t <= 15) indicating the number of test cases.
The first line of each test case contains an integer n. (1 <= n <= 15)
The next line contains N integers Li indicating the length of each fence segment. (1 <= LI <= 10000)

 

Outputfor each test case, output one integer indicating the number of different pastures.

 

Sample input1 3 2 3 4

 

Sample output1

 

Source2012 ACM/ICPC Asia Regional Changchun online

 

Recommendliuyiding It is just a search. It is still a smooth question in the Changchun cyber competition. Search questions... It's better. I use map to determine the weight, and pay attention to a few places to cut, otherwise it will be TLE.
# Include <stdio. h> # Include <Math. h> # Include <Iostream> # Include <Algorithm> # Include <Map> Using   Namespace  STD;  Const   Int Maxn = 20 ;  Int  A [maxn]; Map < Long   Long , Int > MP;  Int  Tol;  Int  N;  Int  SUM;  Void DFS ( Int L1, Int L2,Int L3, Int  I ){  If (L1> L2) Swap (L1, L2 );  If (L1> L3) Swap (L1, L3 );  If (L2> L3) Swap (L2, L3 );  If (L3 * 2 > Sum) Return  ;  If (I =N ){  If (L1 + L2> L3 ){  Long   Long T = L1 * 150000 * 150000 + L2 * 150000 + L3;  If (MP [T] = 0  ) {MP [T] = 1  ; Tol ++ ;}}  Return  ;}  Int T11 = l1 + A [I + 1  ];  Int T12 = L2;  Int T13 = L3;  If (T11> T12) Swap (T11, T12 );  If (T11> T13) Swap (T11, t13 ); If (T12> T13) Swap (T12, t13); DFS (T11, T12, t13, I + 1  );  Int T21 = L1;  Int T22 = l2 + A [I + 1  ];  Int T23 = L3;  If (T21> T22) Swap (T21, T22 );  If (T21>T23) Swap (T21, T23 );  If (T22> T23) Swap (T22, T23 );  If (T11! = T22 | T12! = T22 | t13! = T23) DFS (T21, T22, T23, I + 1  );  Int T31 = L1;  Int T32 = L2;  Int T33 = L3 + A [I + 1  ];  If (T31>T32) Swap (t31, T32 );  If (T31> T33) Swap (t31, t33 );  If (T32> T33) Swap (T32, t33 );  If (T31! = T11 | T32! = T12 | t33! = T13)  If (T31! = T21 | T32! = T22 | t33! = T23) DFS (t31, T32, t33, I + 1  );}  Int  Main (){  Int T; scanf (  "  % D  " ,& T );  While (T -- ) {Scanf (  "  % D  " ,& N); sum = 0  ;  For ( Int I =1 ; I <= N; I ++) {scanf ( "  % D  " , & A [I]); sum + = A [I];} MP. Clear (); Tol = 0  ; DFS (  0 , 0 , 0 , 0  ); Printf (  "  % D \ n  " , Tol );}  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.