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

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

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

改一下模板即可

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

  1. // <4672.cpp> - Sun Oct 9 12:58:23 2016
  2. // This file is made by YJinpeng,created by XuYike's black technology automatically.
  3. // Copyright (C) 2016 ChangJun High School, Inc.
  4. // I don't know what this program is.
  5.  
  6. #include <iostream>
  7. #include <vector>
  8. #include <algorithm>
  9. #include <cstring>
  10. #include <cstdio>
  11. #include <cstdlib>
  12. #include <cmath>
  13. #define MOD 1000000007
  14. #define INF 1e9
  15. #define IN inline
  16. #define RG register
  17. using namespace std;
  18. typedef long long LL;
  19. typedef long double LB;
  20. const int MAXN=100010;
  21. const int MAXM=100010;
  22. inline int max(int &x,int &y) {return x>y?x:y;}
  23. inline int min(int &x,int &y) {return x<y?x:y;}
  24. inline LL gi() {
  25. register LL w=0,q=0;register char ch=getchar();
  26. while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
  27. if(ch=='-')q=1,ch=getchar();
  28. while(ch>='0'&&ch<='9')w=w*10+ch-'0',ch=getchar();
  29. return q?-w:w;
  30. }
  31. struct MAX_CLIQUE{
  32. static const int N=26;
  33. bool G[N][N];
  34. int n,Max[N],Alt[N][N],ans,a[N];
  35. void DFS(int cur,int x,int tot){
  36. if(!cur){
  37. if(tot>ans)ans=tot;
  38. return;
  39. }
  40. for(int i=1;i<=cur;i++){
  41. int u=Alt[x][i],nxt=0;
  42. if(Max[u]+tot<=ans)return;
  43. for(int j=i+1;j<=cur;j++)
  44. if(G[u][Alt[x][j]])Alt[x+1][++nxt]=Alt[x][j];
  45. DFS(nxt,x+1,tot+a[u]);
  46. }
  47. }
  48. int MaxClique(){
  49. ans=0,memset(Max,0,sizeof(Max));
  50. for(int i=n;i;i--){
  51. int cur=0;
  52. for(int j=i+1;j<=n;j++)
  53. if(G[i][j])Alt[1][++cur]=j;
  54. DFS(cur,1,a[i]);
  55. Max[i]=ans;
  56. }
  57. return ans;
  58. }
  59. void Work(){
  60. n=gi();int m=gi();
  61. for(int i=1;i<=n;i++)a[i]=gi();
  62. for(int i=1;i<=m;i++){
  63. int u=gi(),v=gi();
  64. G[u][v]=G[v][u]=1;
  65. }
  66. for(int i=1;i<=n;i++)
  67. for(int j=1;j<=n;j++)
  68. G[i][j]^=1;
  69. printf("%d",MaxClique());
  70. }
  71. }Group;
  72. int main()
  73. {
  74. freopen("4672.in","r",stdin);
  75. freopen("4672.out","w",stdout);
  76. Group.Work();
  77. return 0;
  78. }

  

【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. java常见日期格式转换以及日期的获取

    package com.test.TestBoot.SingleModel;import java.text.SimpleDateFormat;import java.util.Date;public ...

  2. linux ping-测试主机之间网络的连通性

    博主推荐:更多网络测试相关命令关注 网络测试  收藏linux命令大全 ping命令用来测试主机之间网络的连通性.执行ping指令会使用ICMP传输协议,发出要求回应的信息,若远端主机的网络功能没有问 ...

  3. 如何判断CPU、内存、磁盘的性能瓶颈?

    1.如何判断CPU.内存.磁盘的瓶颈? CPU瓶颈1) 查看CPU利用率.建议CPU指标如下 a) User Time:65%-70% b) System Time:30%-35% c) Idle:0 ...

  4. docsearch & algolia

    docsearch & algolia The easiest way to add search to your documentation. https://community.algol ...

  5. parse XML & JSON & js

    parse XML & JSON & js how to parse xml data into json in js? https://stackoverflow.com/quest ...

  6. 天才的记忆(vijos 1514)

    描述 从前有个人名叫W and N and B,他有着天才般的记忆力,他珍藏了许多许多的宝藏.在他离世之后留给后人一个难题(专门考验记忆力的啊!),如果谁能轻松回答出这个问题,便可以继承他的宝藏.题目 ...

  7. 自定义View实现跟随手指的小球

    package com.pingyijinren.test; import android.content.Context; import android.graphics.Canvas; impor ...

  8. 硬盘安装Win 7系统Windows 7 系统硬盘安装教程(图解)

    目前,win 7的市场占有率即将超过XP成为了第一大系统,很多人也用上了win 7,你是不是也还是徘徊呢?是否因为XP用习惯了,或者是不会安装 win7呢?win7安装其实不麻烦,不管是什么系统,安装 ...

  9. 用jQuery向div中添加Html文本内容

    前台代码: <link href="http://www.cnblogs.com/Content/themes/base/jquery-ui.css" rel="s ...

  10. 无法打开物理文件 "X.mdf"。操作系统错误 5:"5(拒绝访问。)"。 (Microsoft SQL Server,错误: 5120)解决

    环境 SQLServer 2008 R2 问题 附加数据库出现“无法打开物理文件 "X.mdf".操作系统错误 5:"5(拒绝访问.)". (Microsoft ...