poj2531 (Network saboteur)

Source: Internet
Author: User

Title Address: Network saboteur

Main topic:

A school's network consists of n computers, in order to reduce traffic between network nodes, the school will divide n nodes into two sets (A, B), student Vasya intends to invade the school network, resulting in the largest flow between the collection, The flow meter between the collections is the sum of the traffic from all nodes in the A collection to all nodes in the B collection.

For example, 1, 2, 3

Decomposition set, a can be {1} at this time B is {2, 3}. Then calculate 1-2 of the traffic plus 1-3 of the traffic for sum to find out all the possible sum to take the largest one.

Problem Solving Ideas:

Test instructions may be a bit difficult to understand. Data is very water and directly enumerates violence. (It should be timed out as usual)

Code:

1#include <algorithm>2#include <iostream>3#include <sstream>4#include <cstdlib>5#include <cstring>6#include <cstdio>7#include <string>8#include <bitset>9#include <vector>Ten#include <queue> One#include <stack> A#include <cmath> -#include <list> - //#include <map> the#include <Set> - using namespacestd; - /***************************************/ - #definell Long Long + #defineInt64 __int64 - #definePI 3.1415927 + /***************************************/ A Const intINF =0x7f7f7f7f; at Const DoubleEPS = 1e-8; - Const DoublePie=acos (-1.0); - Const intd1x[]= {0,-1,0,1}; - Const intd1y[]= {-1,0,1,0}; - Const intd2x[]= {0,-1,0,1}; - Const intd2y[]= {1,0,-1,0}; in Const intfx[]= {-1,-1,-1,0,0,1,1,1}; - Const intfy[]= {-1,0,1,-1,1,-1,0,1}; to Const intdirx[]= {-1,1,-2,2,-2,2,-1,1}; + Const intdiry[]= {-2,-2,-1,-1,1,1,2,2}; - /*Vector <int>map[n];map[a].push_back (b); int len=map[v].size ();*/ the /***************************************/ * voidOpenFile () $ {Panax NotoginsengFreopen ("data.in","RB", stdin); -Freopen ("Data.out","WB", stdout); the } +priority_queue<int>Qi1; Apriority_queue<int, vector<int, greater<int> >Qi2; the /********************** Gorgeous split line, above for template part *****************/ + intmap[ -][ -]; - intvis[ -]; $ intMaxx; $ intN; - intDFS (intXintsum) - { the     inti,j; -      for(i=1; i<=n; i++)Wuyi     { the         if(Vis[i]) -              for(j=1; j<=n; J + +) Wu             { -                 if(!Vis[j]) Aboutsum+=Map[i][j]; $             } -     } -     if(sum>Maxx) -maxx=sum; A      for(i=x; i<=n; i++) +     { thevis[i]=1; -DFS (i+1,0); $vis[i]=0; the     } the } the intMain () the { -      while(SCANF ("%d", &n)! =EOF) in     { thememset (Map,0,sizeof(map)); thememset (Vis,0,sizeof(Vis)); About         inti,j; the          for(i=1; i<=n; i++) the              for(j=1; j<=n; J + +) thescanf"%d",&map[i][j]); +vis[1]=1; -maxx=-1; theDFS (2,0);Bayiprintf"%d\n", Maxx); the     } the     return 0; -}
View Code

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.