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<<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; -}