CSU-ACM2016 Summer Camp Training 2-dfs (c-network saboteur)

Source: Internet
Author: User

C-network saboteur

Time Limit: 2000MS Memory Limit:65536KB 64bit IO Format:%lld &%llu

Description

A University Network is composed of N computers. System administrators gathered information on the traffic between nodes, and carefully divided the network into and the subnet Works in order to minimize traffic between parts.
A disgruntled computer science student Vasya, after being expelled from the university, decided to has his revenge. He hacked into the university network and decided to reassign computers to maximize the traffic between.
Unfortunately, he found, calculating such worst subdivision is one of the those problems he, being a student, failed to so Lve. So he asks-a more successful CS student, to-help him.
The traffic data is given in the form of Matrix C, where Cij is the amount of data sent between and ith jth (nodes = Cji, Cii = 0). The goal is to divide the network nodes into the and the disjointed subsets A and B so as to maximize the SUM∑CIJ (I∈A,J∈B).

Input

The first line of input contains a number of nodes N (2 <= n <= 20). The following n lines, containing n space-separated integers each, represent the traffic matrix C (0 <= Cij <= 10000 ).
Output file must contain a single integer-the maximum traffic between the subnetworks.

Output

Output must contain a single integer-the maximum traffic between the subnetworks.

Sample Input

30 50 3050 0 4030 40 0

Sample Output

90


The idea of solving problems: given an adjacency matrix, it is required to divide the vertices into a and b two sets, so that the sum of the distances of all vertices in the a set to all the vertices in the B collection is the largest.
First, the representation of two sets is in a one-dimensional array a[], where a[i]=1, which indicates that node I is in set a and 0 is in set B.
Two-bit array c[][] stores the adjacency matrix,
Since each number has two choices of 0 and 1, the structure applies depth precedence: Starting with the first number a[0]=1 (assuming that the No. 0 vertex must be in set a),
The 2nd Vertex has two cases for 0, and so on, the structure comes out. The recursive exit is reached at Vertex n-1.
Summation uses two for loops plus the determination of the existence set, records the maximum value, each time the sum result is compared to the maximum value, and if larger, modifies the maximum value.

Harvest Impressions: Depth First has a deeper understanding, just beginning to write the idea of a little confusion, do not know how to write recursion, export also made a mistake, over and over the process of deep understanding.
#include <iostream>#include<stdio.h>#include<cstring>using namespacestd;inta[ +],b[ +],c[ +][ +],n,sum,tp=0, tp2=0;voidBFsintTpintl);intMain () {memset (A,0, +); //memset (b,-1,21);     while(SCANF ("%d", &n)! =EOF) {     for(intI=0; i<n;i++)     for(intj=0; j<n;j++) scanf ("%d",&C[i][j]); BFS (0,1); printf ("%d\n", sum); }    return 0;}voidBFsintTpintl) {    if(tp==n| | tp==-1)return; ints=0; A[TP]=l;  for(intI=0; i<n;i++)    {        if(a[i]==1)         for(intj=0; j<n;j++)        {            if(a[j]==0) s=s+C[i][j]; }    }    if(sum<s) sum=s; BFS (TP+1,1); BFS (TP+1,0);}

CSU-ACM2016 Summer Camp Training 2-dfs (c-network saboteur)

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.