zoukankan      html  css  js  c++  java
  • Network Saboteur POJ

    A university network is composed of N computers. System administrators gathered information on the traffic between nodes, and carefully divided the network into two subnetworks in order to minimize traffic between parts. 
    A disgruntled computer science student Vasya, after being expelled from the university, decided to have his revenge. He hacked into the university network and decided to reassign computers to maximize the traffic between two subnetworks. 
    Unfortunately, he found that calculating such worst subdivision is one of those problems he, being a student, failed to solve. So he asks you, a more successful CS student, to help him. 
    The traffic data are given in the form of matrix C, where Cij is the amount of data sent between ith and jth nodes (Cij = Cji, Cii = 0). The goal is to divide the network nodes into the two 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

    3
    0 50 30
    50 0 40
    30 40 0
    

    Sample Output

    90
    DFS
     1 #include <iostream>
     2 using namespace std;
     3 #include<string.h>
     4 #include<set>
     5 #include<stdio.h>
     6 #include<math.h>
     7 #include<queue>
     8 #include<map>
     9 #include<algorithm>
    10 int a[22][22];
    11 int t;
    12 int b[22];
    13 int i,j;
    14 int sum1=0;
    15 void dfs(int q,int sum)
    16 {
    17     if(q>t)
    18         {
    19             if(sum>sum1)
    20                 sum1=sum;
    21             return;
    22         }
    23     int m=0;
    24     b[q]=1;
    25     for(i=1;i<=q;i++)
    26     if(b[i]==0)
    27     m+=a[i][q];
    28     dfs(q+1,sum+m);
    29 
    30     b[q]=0;
    31     m=0;
    32     for(i=1;i<=q;i++)
    33     if(b[i]==1)
    34     m+=a[i][q];
    35     dfs(q+1,sum+m);
    36 }
    37 int main()
    38 {
    39     cin>>t;
    40     for(i=1;i<=t;i++)
    41         for(j=1;j<=t;j++)
    42         cin>>a[i][j];
    43         dfs(1,0);
    44         cout<<sum1<<endl;
    45     return 0;
    46 }
    View Code
  • 相关阅读:
    文件下载
    字符串截取
    GAMES101 作业1
    GAMES101 作业0
    常见的企业管理系统有哪些
    Spring---AoP(面向切面编程)原理学习笔记【全】
    什么是OOP(Object Oriented Programming)面向对象编程
    Spring框架之控制反转IoC(Inversion of Control)的理解
    Typora编辑器MarkDown语法
    国民经济行业分类与代码(GB/T 4754-2017、GB/T 4754-2011、GB/T 4754-2002)
  • 原文地址:https://www.cnblogs.com/dulute/p/7272640.html
Copyright © 2011-2022 走看看