Battle for Silve |
Time Limit: 3000ms, Special Time Limit:7500ms, Memory Limit:65536KB |
Total submit users: 9, Accepted users: 8 |
Problem 12948 : No special judgement |
Problem 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. 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: |
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 6 100 5000 1000 2000 1 2 1 3 1 4 2 3 2 4 3 4 6 8 1500 1000 100 2000 500 300 1 2 1 3 1 4 2 4 3 5 4 5 4 6 5 6 |
Sample Output |
8100 4500 |
给出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 __int64
using 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;
}