hnu 12948

来源:互联网 发布:网络安全技术题 编辑:程序博客网 时间:2024/05/16 12:44

Battle for SilveTime Limit: 3000ms, Special Time Limit:7500ms, Memory Limit:65536KBTotal submit users: 9, Accepted users: 8Problem 12948 : No special judgementProblem description

Piet Hein was a Dutch naval officer during the Eighty Years’ War between the United Provinces of The Netherlands and Spain. His most famous victory was the capture of the Zilvervloot (‘Silver Fleet’) near Cuba in 1628, where he intercepted a number of Spanish vessels that were carrying silver from the Spanish colonies in the Americas to Spain. Details about this famous naval battle are sketchy, so the description below may contain some historical inaccuracies.

The Silver Fleet consisted of vessels containing silver coins. Piet Hein’s basic strategy was simple: tow away a number of vessels from the fleet, in order to capture their contents.

In an attempt to prevent the Dutch from carrying out this plan, the Spanish tied all the ships in their fleet together using huge iron chains. Each vessel in their fleet was fixed to at least one other vessel; any two vessels were connected by at most one chain; and the Spanish made sure that the chains did not cross each other, otherwise they could get tied up into a knot. As an end result, the vessels and the chains connecting them formed a connected, planar graph.

However, the Spanish preventive measures only made their situation worse. As an experienced naval officer, Piet Hein knew that towing away a group of ships was easiest if, for every two ships in the group, the ships were connected by a chain. He called such groups chaingroups.

Piet Hein ordered his men to tow away all the ships in the chaingroup that contained the largest amount of booty, after severing the links with the remaining ships in the Spanish fleet with a few highly accurate canon shots. The total booty in a chaingroup is the total number of silver coins in the vessels that make up the chaingroup.

Given a description of the Silver Fleet, find the value of the chaingroup with the highest amount of booty (i.e., total number of silver coins in the ships that make up the chaingroup).


Input

For each test-case:

• A line containing two integers v (2 ≤ v ≤ 450) and e (1 ≤ e ≤ 900), the number of vessels in the fleet and the number of chains, respectively.

• Then, v lines specifying S1,S2,...,Sv, the amount of silver coins carried by vessel i (1 ≤ i ≤ v). The Siwill be positive integers, where 100 ≤ Si≤ 6000.

• Then, for each chain, a line containing two integers cstartand cend, the two vessels connected by the chain, where (1 ≤ cstart< cend≤ v).

Each fleet forms a connected, planar graph.


Output

For each test case, one line containing a single positive integer: the number of silver coins that is captured by Piet Hein’s fl


Sample Input
4 61005000100020001 21 31 42 32 43 46 81500100010020005003001 21 31 42 43 54 54 65 6
Sample Output
81004500

给出v个点  有e条边  每个点都有一个权值  

题目要求是在给的点个边中找到一个团 团中每两个点之间都有一条边  且要求边不能交叉

找到符合要求的且所有点权值和最大的团就可以了

符合要求的团点数最多有四个(为什么是四个呢。。。不是很理解 我觉得是三个的。。。但是样例中给出的有四个的。。就蒙了下。。四个点的时候 两条对角线不就相交了嘛)

dfs暴搜  判断这个点能不能与之前的点一起组成团 

点的权值和要取最大值

#include <cstdio>#include <iostream>#include <cstring>#include <cmath>#include <algorithm>#include <string.h>#include <string>#define eps 1e-8#define op operator#define MOD  10009#define MAXN  100100#define FOR(i,a,b)  for(int i=a;i<=b;i++)#define FOV(i,a,b)  for(int i=a;i>=b;i--)#define REP(i,a,b)  for(int i=a;i<b;i++)#define REV(i,a,b)  for(int i=a-1;i>=b;i--)#define MEM(a,x)    memset(a,x,sizeof a)#define ll __int64using namespace std;int a[460];int map[460][460];int vis[460];int ans;int n,m;int tuan[10];bool istuan(int num,int x){    for(int i=0;i<num;i++)    {        if(!map[tuan[i]][x])  return 0;//没有边 不能构成团    }    return 1;}void dfs(int num,int p,int sum){    ans=max(ans,sum);    if(num==4)  return;    for(int i=p+1;i<=n;i++)    {        if(vis[i]||!istuan(num,i))  continue;        tuan[num]=i;        vis[i]=1;//        sum+=a[i];        dfs(num+1,i,sum+a[i]);        vis[i]=0;    }//    return;}int main(){freopen("ceshi.txt","r",stdin);    while(scanf("%d%d",&n,&m)!=EOF)    {        MEM(map,0);  MEM(vis,0);        for(int i=1;i<=n;i++)            scanf("%d",&a[i]);        for(int i=0;i<m;i++)        {            int x,y;            scanf("%d%d",&x,&y);            map[x][y]=map[y][x]=1;        }        ans=0;        dfs(0,0,0);        printf("%d\n",ans);    }    return 0;}




0 0
原创粉丝点击