HDU 4277 usaco orz (brute force search + set deduplication)

Source: Internet
Author: User

Enumeration 3 ^ 15 cases, different triangles are deduplicated with set.

Add an edge to all segments, move them one by one to the other, and enumerate all the conditions.

Stuck in the past ...........

 

Include <cstdio> # include <cmath> # include <iostream> # include <algorithm> # include <cstring> # include <set> using namespace std; int a [22]; int n; int sum, ans, flag; struct node {int x, y, z; bool operator <(const node & a) const {if (. x! = X) return a. x <x; if (a. y! = Y) return. y <y; return. z <z ;}}; set <node> s; // custom set void init () {s. clear ();} void dfs (int v0, int v1, int v2, int I) {if (I> = n) return; if (v0 + v1> v2 & v0 + v2> v1 & v1 + v2> v0) {int a1, a2, a3, tmp; node t; a1 = v0; a2 = v1; a3 = v2; if (a2> a3) {swap (a2, a3);} if (a1> a2) {swap (a1, a2 );} if (a2> a3) {swap (a2, a3);} t. x = a1; t. y = a2; t. z = a3; s. insert (t);} // three options for each I If (v0 + v1-a [I]> v2 + a [I]) dfs (v0-a [I], v1, v2 + a [I], I + 1); if (v0 + v2-a [I]> v1 + a [I]) dfs (v0-a [I], v1 + a [I], v2, I + 1); dfs (v0, v1, v2, I + 1);} int main () {int T; cin> T; while (T --) {init (); scanf ("% d", & n); sum = 0; for (int I = 0; I <n; I ++) {scanf ("% d", & a [I]); sum + = a [I];} dfs (sum, 0, 0 ); printf ("% d \ n", s. size () ;}return 0 ;}# include <cstdio >#include <cmath >#include <iostream> # inclu De <algorithm> # include <cstring> # include <set> using namespace std; int a [22]; int n; int sum, ans, flag; struct node {int x, y, z; bool operator <(const node & a) const {if (. x! = X) return a. x <x; if (a. y! = Y) return. y <y; return. z <z ;}}; set <node> s; // custom setvoid init () {s. clear ();} void dfs (int v0, int v1, int v2, int I) {if (I> = n) return; if (v0 + v1> v2 & v0 + v2> v1 & v1 + v2> v0) {int a1, a2, a3, tmp; node t; a1 = v0; a2 = v1; a3 = v2; if (a2> a3) {swap (a2, a3);} if (a1> a2) {swap (a1, a2 );} if (a2> a3) {swap (a2, a3);} t. x = a1; t. y = a2; t. z = a3; s. insert (t);} // For each I, select if (v0 + v1-a [I]> v2 + a [I]) dfs (v0-a [I], v1, v2 + a [I], I + 1); if (v0 + v2-a [I]> v1 + a [I]) dfs (v0-a [I], v1 + a [I], v2, I + 1); dfs (v0, v1, v2, I + 1 );} int main () {int T; cin> T; while (T --) {init (); scanf ("% d", & n); sum = 0; for (int I = 0; I <n; I ++) {scanf ("% d", & a [I]); sum + = a [I];} dfs (sum, 0, 0); printf ("% d \ n", s. size () ;}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.