Battle for Silver

Time Limit: 2999/999MS (Java/Others)     Memory Limit: 65432/65432KB (Java/Others)

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 groupschaingroups.

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.

The Silver Fleet represented as a graph: each dot denotes a vessel in the fleet, while each line denotes a chain that connects two vessels. The vessels that are connected in the figure by the dashed lines correspond to the chaingroup that provides the highest total value of silver coins. In this case, Piet Hein loots 4500 silver coins from the fleet.

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 Si will be positive integers, where 100≤Si≤6000.
  • Then, for each chain, a line containing two integers cstart and 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 fleet.

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
解题:dfs搜索。哎,好久未写搜索,当时居然脑残了。
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
bool g[maxn][maxn],done[maxn];
int n,ans,p[maxn],w[maxn];
bool ok(int m,int x){
for(int i = ; i < m; i++)
if(!g[p[i]][x]) return false;
return true;
}
void dfs(int m,int k,int sum){
ans = max(ans,sum);
if(m == ) return;
for(int i = k+; i <= n; i++){
if(!done[i] && ok(m,i)){
done[i] = true;
p[m] = i;
dfs(m+,i,sum+w[i]);
done[i] = false;
}
}
}
int main() {
int i,m,u,v;
while(~scanf("%d %d",&n,&m)){
for(i = ; i <= n; i++)
scanf("%d",w+i);
memset(g,false,sizeof(g));
for(i = ; i < m; i++){
scanf("%d %d",&u,&v);
g[u][v] = g[v][u] = true;
}
ans = ;
dfs(,,);
printf("%d\n",ans);
}
return ;
}

CDOJ 889 Battle for Silver的更多相关文章

  1. UVaLive 6623 Battle for Silver (最大值,暴力)

    题意:给定一个图,让你找一个最大的子图,在这个子图中任何两点都有边相连,并且边不交叉,求这样子图中权值最大的是多少. 析:首先要知道的是,要想不交叉,那么最大的子图就是四个点,否则一定交叉,然后就暴力 ...

  2. 2014 UESTC 暑前集训队内赛(3) 部分解题报告

    B.Battle for Silver 定理:完全图Kn是平面图当且仅当顶点数n<=4. 枚举所有完全图K1,K2,K3,K4,找出最大总权重. 代码: #include <iostrea ...

  3. CDOJ 1220 The Battle of Guandu

    The Battle of Guandu Time Limit: 6000/3000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Oth ...

  4. CDOJ 1217 The Battle of Chibi

    The Battle of Chibi Time Limit: 6000/4000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Othe ...

  5. cdoj 树上战争(Battle on the tree) Label:并查集?

    给一棵树,如果树上的某个节点被某个人占据,则它的所有儿子都被占据,lxh和pfz初始时分别站在两个节点上,谁当前所在的点被另一个人占据,他就输了比赛,问谁能获胜. Input 输入包含多组数据 每组第 ...

  6. CDOJ UESTC 1220 The Battle of Guandu

    The 2015 China Collegiate Programming Contest 2015第一届中国大学生程序设计竞赛 F题 本质就是求单源最短路!注意会爆int 对于每一个村庄i,其实就是 ...

  7. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  8. USACO翻译:USACO 2013 NOV Silver三题

    USACO 2013 NOV SILVER 一.题目概览 中文题目名称 未有的奶牛 拥挤的奶牛 弹簧牛 英文题目名称 nocow crowded pogocow 可执行文件名 nocow crowde ...

  9. USACO翻译:USACO 2013 DEC Silver三题

    USACO 2013 DEC SILVER 一.题目概览 中文题目名称 挤奶调度 农场航线 贝西洗牌 英文题目名称 msched vacation shuffle 可执行文件名 msched vaca ...

随机推荐

  1. C#在WinForm中使用WebKit传递js对象实现与网页交互的方法

    这篇文章主要介绍了C#在WinForm中使用WebKit传递js对象实现与网页交互的方法,涉及针对WebBroswer控件及WebKit控件的相关使用技巧,需要的朋友可以参考下 本文实例讲述了C#在W ...

  2. 【POJ 2018】 Best Cow Fences

    [题目链接] http://poj.org/problem?id=2018 [算法] 二分平均值 检验时将每个数减去二分的值,求长度至少为L的子序列和的最大值,判断是否大于0 [代码] #includ ...

  3. P5058 [ZJOI2004]嗅探器 tarjan割点

    这个题是tarjan裸题.最后bfs暴力找联通块就行.(一开始完全写错了竟然得了70分,题意都理解反了...这数据强度...) 题干: 题目描述 某军搞信息对抗实战演习,红军成功地侵入了蓝军的内部网络 ...

  4. Vue 页面回退参数被当作字符串处理

    当时情景是这样的,我从A页面跳到B页面时会传一个Boolean类型的参数,当B跳到C,再从C返回B的时候,控制台打印发现参数还在,可是判断怎么都不起作用,后来发现,当页面返回的时候,默认将参数变成了字 ...

  5. GIT分支的一些开发心得

    从本地的master分支创建新的分支 $ git checkout -b dev Switched to a new branch 'dev' 上面那条命令可以分为两步 $ git branch de ...

  6. BZOJ 1137 半平面交

    半平面交的板子 //By SiriusRen #include <bits/stdc++.h> #define double long double using namespace std ...

  7. Codeforces 825D 二分贪心

    题意:给一个 s 串和 t 串, s 串中有若干问号,问如何填充问号使得 s 串中字母可以组成最多的 t 串.输出填充后的 s 串. 思路:想了下感觉直接怼有点麻烦,要分情况:先处理已经可以组成 t ...

  8. UNIX环境高级编程--8. 进程控制

    进程控制进程标识:    每一个进程都有一个非负整型表示的唯一进程ID.虽然唯一,但是ID可以复用.当一个进程结束后,其进程ID会被延迟复用.    ID=0的进程通常是调度进程,常被称作交换进程(s ...

  9. 微信接口本地调试(IIS服务器)

    1.下载ngrok,并注册获得token.官网下载地址:https://ngrok.com/ 如果你是在官网下载的,到后面映射域名的时候会要求购买他们的服务. 这里我们用一个国内免费的ngrok服务器 ...

  10. 小小的IP,大大的耦合,你痛过吗?

    什么是耦合? 耦合,是架构中,本来不相干的代码.模块.服务.系统因为某些原因联系在一起,各自独立性差,影响则相互影响,变动则相互变动的一种架构状态. 感官上,怎么发现系统中的耦合? 作为技术人,每每在 ...