poj2531(Network Saboteur)

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   io   資料   for   

題目地址: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 long19 #define int64 __int6420 #define PI 3.141592721 /***************************************/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\n",maxx);82     }83     return 0;84 }
View Code

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.