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
  • 相关阅读:
    SpringMvc与Struts2的对比
    Spring 通知
    Spring 之 AOP
    Spring 之 IOC
    Spring IOC 和 AOP概述
    JSON与JAVA数据的相互转换
    (4)-optXXX方法的使用
    (3)-JSONObject的过滤设置
    (2)-生成JSONObject的方法
    String 类型的相关转换
  • 原文地址:https://www.cnblogs.com/dulute/p/7272640.html
Copyright © 2011-2022 走看看