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
  • 相关阅读:
    angular js模块,angular js控制器
    select ipnut双向数据绑定用法
    ng-repeat循环遍历的用法
    angular js起步
    文件上传(预览2 老师提供的方法)
    设置mui头部(头部与最上面可以设置同样的样子)支持ios (苹果) 安卓不支持
    点击按钮btn 打开(跳转)新的页面
    定位精准 并打印出来
    把原始坐标转化为百度坐标(位置更精确)
    原始地理定位
  • 原文地址:https://www.cnblogs.com/dulute/p/7272640.html
Copyright © 2011-2022 走看看