hnu 12948
来源:互联网 发布:网络安全技术题 编辑:程序博客网 时间:2024/05/16 12:44
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 6Sample 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;}
- hnu 12948
- HNU 11877
- hnu 病毒
- HNU Profits
- HNU 21
- acm hnu 10136 Palindromes
- hnu 12029 LCA问题
- hnu 12439 #贪心
- [讨论]hnu 12450 Painting
- hnu-City Merger
- hnu-Kitchen Robot
- HNU 12813 Restore Calculation
- HNU 12834 Thread Tree
- acm HNU Dwarf Tower
- HNU 12836 Fox Observation
- HNU 12850 Garage
- HNU 12894 Keys
- HNU 12870 Selection
- html小知识12
- UVa 572 油田
- git简介
- First Date
- 如何应对危机
- hnu 12948
- Boxes and Stones - UVa 12525 dp
- 易语言写dll,vc调用
- eclipse中的maven web项目报错:org/codehaus/plexus/archiver/jar/JarArchiver
- poj2190
- “赢在中国”点评人给80后年轻人的30个忠告
- iOS 开发常用宏定义
- C++设计模式之外观模式(三)
- 【HEVC学习与研究】34、HEVC参考软件HM中Intra预测参考像素的获取与管理