• poj2531(Network Saboteur)


    题目地址:Network Saboteur

    题目大意:

        一个学校的网络由N台计算机组成,为了减少网络节点之间的流量,学校将N个节点分解成两个集合(A、B),student Vasya打算入侵学校的网络,致使集合之间的流量最大,集合之间的流量计算是A集合中的所有节点到B集合中的所有节点的流量之和。

    例如 1、2、3

    分解集合,A可以为{1}这时B为{2、3}。然后计算 1-2的流量加上 1-3的流量为sum  求出所有可能的sum  取最大的那个。

    解题思路:

        题意可能有点难理解。  数据很水,直接枚举暴力。(照常理应该会超时)

    代码:

     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>
    10 #include <queue>
    11 #include <stack>
    12 #include <cmath>
    13 #include <list>
    14 //#include <map>
    15 #include <set>
    16 using namespace std;
    17 /***************************************/
    18 #define ll long long
    19 #define int64 __int64
    20 #define PI 3.1415927
    21 /***************************************/
    22 const int INF = 0x7f7f7f7f;
    23 const double eps = 1e-8;
    24 const double PIE=acos(-1.0);
    25 const int d1x[]= {0,-1,0,1};
    26 const int d1y[]= {-1,0,1,0};
    27 const int d2x[]= {0,-1,0,1};
    28 const int d2y[]= {1,0,-1,0};
    29 const int fx[]= {-1,-1,-1,0,0,1,1,1};
    30 const int fy[]= {-1,0,1,-1,1,-1,0,1};
    31 const int dirx[]= {-1,1,-2,2,-2,2,-1,1};
    32 const int diry[]= {-2,-2,-1,-1,1,1,2,2};
    33 /*vector <int>map[N];map[a].push_back(b);int len=map[v].size();*/
    34 /***************************************/
    35 void openfile()
    36 {
    37     freopen("data.in","rb",stdin);
    38     freopen("data.out","wb",stdout);
    39 }
    40 priority_queue<int> qi1;
    41 priority_queue<int, vector<int>, greater<int> >qi2;
    42 /**********************华丽丽的分割线,以上为模板部分*****************/
    43 int map[25][25];
    44 int vis[25];
    45 int maxx;
    46 int n;
    47 int DFS(int x,int sum)
    48 {
    49     int i,j;
    50     for(i=1; i<=n; i++)
    51     {
    52         if (vis[i])
    53             for(j=1; j<=n; j++)
    54             {
    55                 if (!vis[j])
    56                     sum+=map[i][j];
    57             }
    58     }
    59     if (sum>maxx)
    60         maxx=sum;
    61     for(i=x; i<=n; i++)
    62     {
    63         vis[i]=1;
    64         DFS(i+1,0);
    65         vis[i]=0;
    66     }
    67 }
    68 int main()
    69 {
    70     while(scanf("%d",&n)!=EOF)
    71     {
    72         memset(map,0,sizeof(map));
    73         memset(vis,0,sizeof(vis));
    74         int i,j;
    75         for(i=1; i<=n; i++)
    76             for(j=1; j<=n; j++)
    77                 scanf("%d",&map[i][j]);
    78         vis[1]=1;
    79         maxx=-1;
    80         DFS(2,0);
    81         printf("%d
    ",maxx);
    82     }
    83     return 0;
    84 }
    View Code
  • 相关阅读:
    Spring中配置和读取多个Properties文件
    python 数据清洗
    python excel 文件合并
    Pandas -- Merge,join and concatenate
    python 数据合并
    python pandas
    python Numpy
    EXCEL 导入 R 的几种方法 R—readr和readxl包
    R语言笔记完整版
    第十三章 多项式回归分析
  • 原文地址:https://www.cnblogs.com/ZhaoPengkinghold/p/3896462.html
Copyright © 2020-2023  润新知