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. bzoj1008 [HNOI2008]越狱——快速幂

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1008 (这样一道水题还因为忘记写 %lld WA了那么多遍) 发生越狱的状态数,就是全部状态 ...

  2. java 监听机制模拟(JButton按钮监听机制)

    一.概念 1.事件监听器 事件监听器就我个人的理解就是:被外部事件(键盘.鼠标)引发的程序,这段程序是被嵌入到事件源的类里面,它负责监听事件列表.而很多人把事件监听器理解成是实现EventListen ...

  3. form表单点击后验证

    function check(){ var customertype = document.getElementById("customertype"); //alert(cust ...

  4. VUE修改每个页面title

    //index.js routes: [ { name:'home', path: '/home/:openname', component: Home, meta: { title: '首页' } ...

  5. struts2.1.6存在中文乱码的bug

    如题,后续版本中已解决:可以通过添加filter的方式解决.

  6. SAS进阶《深入解析SAS》之对多数据集的处理

    SAS进阶<深入解析SAS>之对多数据集的处理 1. 数据集的纵向串接: 数据集的纵向串接指的是,将两个或者多个数据集首尾相连,形成一个新的数据集. 据集的横向合并: 数据集的横向合并,指 ...

  7. python gdal 数组生成图片

    cols = array.shape[1]rows = array.shape[0]originX = rasterOrigin[0]originY = rasterOrigin[1]driver = ...

  8. echarts交叉关系图二

    echarts关系图表,此图是坐标关系图,此图用的随机坐标,此图可以拖拽,更方便整理关系, 引入echarts.js就可以实现 代码: var graph={ //这是数据项目中一般都是获取到的 no ...

  9. JS——动态添加事件和移除事件(有待补充...)

    动态的添加事件:利用 attachEvent 和 addEventListener IE 支持 attachEvent: obj.attachEvent("onclick", Fo ...

  10. SQL Server建库-建表-建约束

    ----------------------------------------SQL Server建库-建表-建约束创建School数据库------------------------------ ...