POJ 2531 Network saboteur Problem Solving report

Source: Internet
Author: User

Title Link: http://poj.org/problem?id=2531

The topic meaning: divide n points into two parts A and B (that is, two subsets), make the subset and maximum (it must be difficult to understand, hehe). For example, the best method for a sample is to divide the point 2 into a subset, and the other subset is 1, 3. The weight of 2-1 is the weight of the 50,2-3 is 40, then the largest is 50+40 = 90.

First DFS, I'm not very good at it. See the captain of the use of state compression to do, suddenly feel good magic!!!!

Perhaps the first contact, understanding is not too deep, first keep it. It feels so magical and magical .... Good magic ... But always think it's time to judge a repetition, look at the subset of the first 1:1 subset of 2:2, 3, and the sixth subset of 1:2 3 subset 2:1 is essentially a situation. NOTE: If a subset contains n elements, it means that the other subset has 0 elements, which is obviously not compliant Conditions. Because all points of a subset are required for all points in another sub-set (provided that there are edges connected) and are the largest!

(Sorry Ah, always forcing everyone to see my disgusting graffiti, but I really understand some after the action, this is my graffiti to write the drip)

1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 6 Const intMAXN = -+5;7 intC[MAXN][MAXN];8 intA[MAXN], B[MAXN];//a[]: Used to save the vertex number contained in subset 1; b[]: Used to hold the vertex number contained in subset 29                      //(Note that subscript 0 is the point at which the vertex number is 1)Ten  One intMain () A { -     intN; -      while(SCANF ("%d", &n)! =EOF) the     { -          for(inti =0; I < n; i++) -         { -              for(intj =0; J < N; J + +) +scanf"%d", &c[i][j]); -         } +         intcnt1, Cnt2; A         intAns =-1; at          for(inti =1; I < (1&LT;&LT;N); i++)//number of enumerated subsets, n elements having (2^n-1) subsets (except the empty set) -{//(3 elements have seven subsets (001~111) -Cnt1 = Cnt2 =0; -              for(intj =0; J < N; J + +) -             { -                 if(I & (1<<j)) ina[cnt1++] =J;  -                 Else tob[cnt2++] =J; +             } -              intCursum =0; the               for(intK =0; K < Cnt1; k++) *             { $                  for(intj =0; J < Cnt2; J + +)Panax NotoginsengCursum + =C[a[k]][b[j]]; -             } theAns =Max (cursum, ans); +         } Aprintf"%d\n", ans); the     } +     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.