http://codevs.cn/problem/4672/

那个一看这不是(最大独立集)的最大权值和,类似

反图→ 最大团  NP问题 搜索解决

改一下模板即可

参考最大独立集  Maximum Clique最大团问题

// <4672.cpp> - Sun Oct  9 12:58:23 2016
// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is. #include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define MOD 1000000007
#define INF 1e9
#define IN inline
#define RG register
using namespace std;
typedef long long LL;
typedef long double LB;
const int MAXN=100010;
const int MAXM=100010;
inline int max(int &x,int &y) {return x>y?x:y;}
inline int min(int &x,int &y) {return x<y?x:y;}
inline LL gi() {
register LL w=0,q=0;register char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')q=1,ch=getchar();
while(ch>='0'&&ch<='9')w=w*10+ch-'0',ch=getchar();
return q?-w:w;
}
struct MAX_CLIQUE{
static const int N=26;
bool G[N][N];
int n,Max[N],Alt[N][N],ans,a[N];
void DFS(int cur,int x,int tot){
if(!cur){
if(tot>ans)ans=tot;
return;
}
for(int i=1;i<=cur;i++){
int u=Alt[x][i],nxt=0;
if(Max[u]+tot<=ans)return;
for(int j=i+1;j<=cur;j++)
if(G[u][Alt[x][j]])Alt[x+1][++nxt]=Alt[x][j];
DFS(nxt,x+1,tot+a[u]);
}
}
int MaxClique(){
ans=0,memset(Max,0,sizeof(Max));
for(int i=n;i;i--){
int cur=0;
for(int j=i+1;j<=n;j++)
if(G[i][j])Alt[1][++cur]=j;
DFS(cur,1,a[i]);
Max[i]=ans;
}
return ans;
}
void Work(){
n=gi();int m=gi();
for(int i=1;i<=n;i++)a[i]=gi();
for(int i=1;i<=m;i++){
int u=gi(),v=gi();
G[u][v]=G[v][u]=1;
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
G[i][j]^=1;
printf("%d",MaxClique());
}
}Group;
int main()
{
freopen("4672.in","r",stdin);
freopen("4672.out","w",stdout);
Group.Work();
return 0;
}

  

【Codevs 4672】辛苦的老园丁的更多相关文章

  1. 提高组刷题营 DAY 1 下午

    DFS 深度优先搜索 通过搜索得到一棵树形图 策略:只要能发现没走过的点,就走到它.有多个点可走就随便挑一个,如果无路可走就回退,再看有没有没走过的点可走. 在图上寻找路径[少数可用最短路解决]:最短 ...

  2. codevs 3289 花匠

    题目:codevs 3289 花匠 链接:http://codevs.cn/problem/3289/ 这道题有点像最长上升序列,但这里不是上升,是最长"波浪"子序列.用动态规划可 ...

  3. codevs 1082 线段树练习 3(区间维护)

    codevs 1082 线段树练习 3  时间限制: 3 s  空间限制: 128000 KB  题目等级 : 大师 Master 题目描述 Description 给你N个数,有两种操作: 1:给区 ...

  4. codevs 1285 二叉查找树STL基本用法

    C++STL库的set就是一个二叉查找树,并且支持结构体. 在写结构体式的二叉查找树时,需要在结构体里面定义操作符 < ,因为需要比较. set经常会用到迭代器,这里说明一下迭代器:可以类似的把 ...

  5. codevs 1576 最长上升子序列的线段树优化

    题目:codevs 1576 最长严格上升子序列 链接:http://codevs.cn/problem/1576/ 优化的地方是 1到i-1 中最大的 f[j]值,并且A[j]<A[i] .根 ...

  6. codevs 1080 线段树点修改

    先来介绍一下线段树. 线段树是一个把线段,或者说一个区间储存在二叉树中.如图所示的就是一棵线段树,它维护一个区间的和. 蓝色数字的是线段树的节点在数组中的位置,它表示的区间已经在图上标出,它的值就是这 ...

  7. codevs 1228 苹果树 树链剖分讲解

    题目:codevs 1228 苹果树 链接:http://codevs.cn/problem/1228/ 看了这么多树链剖分的解释,几个小时后总算把树链剖分弄懂了. 树链剖分的功能:快速修改,查询树上 ...

  8. codevs 1082 线段树区间求和

    codevs 1082 线段树练习3 链接:http://codevs.cn/problem/1082/ sumv是维护求和的线段树,addv是标记这歌节点所在区间还需要加上的值. 我的线段树写法在运 ...

  9. codevs 1052 地鼠游戏

    1052 地鼠游戏 http://codevs.cn/problem/1052/ 题目描述 Description 王钢是一名学习成绩优异的学生,在平时的学习中,他总能利用一切时间认真高效地学习,他不 ...

随机推荐

  1. copy on write

    yl::string CBaseAutopProcessor::AddAuthorizedInfo(const yl::string & strOriginalUrl, const yl::s ...

  2. MySql-count(*)与count(id)与count(字段)之间的执行结果和性能分析

    在mysql数据库中,当我们需要统计数据的时候,一定会用到count()这个方法,那么count(值)里面的这个值,到底应该怎么选择呢!常见有3种选择,(*,数字,列名),分别列出它们的执行结果和性能 ...

  3. jQuery的ready与js的load事件的区别

    摘自:http://www.cnblogs.com/see7di/archive/2011/07/15/2239677.html 为了理解这两个事件的异同,读者应该先了解HTML文档加载的顺序. DO ...

  4. PHP:分页类(比较庞大不建议在项目中用)

    文章来源:http://www.cnblogs.com/hello-tl/p/7685178.html <?php //地址 //page::$url=''; //每页的条数 默认10 //pa ...

  5. python中正则表达式与模式匹配

    一.前言 在之前找工作过程中,面试时经常被问到会不会python,懂不懂正则表达式.心里想:软件的东西和芯片设计有什么关系?咱也不知道因为啥用这个,咱也不敢问啊!在网上搜索到了一篇关于脚本在ASIC领 ...

  6. super在python中有什么用

    所属网站分类: python高级 > 面向对象 作者:阿里妈妈 链接:http://www.pythonheidong.com/blog/article/74/ 来源:python黑洞网 有什么 ...

  7. poj 1363 火车进站 (栈的应用)

    Description There is a famous railway station in PopPush City. Country there is incredibly hilly. Th ...

  8. Lucene实现全文检索的流程

    [索引和搜索流程图] 对要索引的原始内容进行索引构建一个索引库,索引过程包括:确定原始内容即要搜索的内容->采集文档->创建文档->分析文档->索引文档. 从索引库中搜索内容, ...

  9. C51 继电器 个人笔记

    一句话 小电流控制大电流的开关. 电路图 给J2端口一个低电平,三极管导通,线圈吸合 一般用P1^4口连接 #include <reg51.h> #define u16 unsigned ...

  10. pdf & background

    pdf & background 设置 chrome pdf background error OK