题意:给定一个图,让你找一个最大的子图,在这个子图中任何两点都有边相连,并且边不交叉,求这样子图中权值最大的是多少。

析:首先要知道的是,要想不交叉,那么最大的子图就是四个点,否则一定交叉,然后就暴力就好,数据水,不会TLE的,才100多ms

代码如下:

    #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 450 + 5;
const int mod = 1e9 + 7;
const char *mark = "+-*";
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
vector<int> G[maxn]; int a[maxn];
int g[maxn][maxn];
int ans;
int pre[10]; void dfs(int u, int d, int val){
ans = Max(ans, val);
if(d == 4) return ; for(int i = 0; i < G[u].size(); ++i){
int v = G[u][i];
bool ok = true;
for(int j = 0; j < d; ++j){
if(!g[v][pre[j]]){ ok = false; break; }
}
for(int j = 0; j < d; ++j)
if(pre[j] == v){ ok = false; break; }
if(!ok) continue;
pre[d] = v;
dfs(v, d+1, val+a[v]);
}
} int main(){
while(scanf("%d %d", &n, &m) == 2){
for(int i = 1; i <= n; ++i){
scanf("%d", &a[i]);
G[i].clear();
}
memset(g, 0, sizeof(g));
for(int i = 0; i < m; ++i){
int u, v;
scanf("%d %d", &u, &v);
g[u][v] = g[v][u] = 1;
G[u].push_back(v);
G[v].push_back(u);
}
ans = 0;
for(int i = 1; i <= n; ++i){
pre[0] = i;
dfs(i, 1, a[i]);
}
printf("%d\n", ans);
}
return 0;
}

  

UVaLive 6623 Battle for Silver (最大值,暴力)的更多相关文章

  1. CDOJ 889 Battle for Silver

    Battle for Silver Time Limit: 2999/999MS (Java/Others)     Memory Limit: 65432/65432KB (Java/Others) ...

  2. UVaLive 6855 Banks (水题,暴力)

    题意:给定 n 个数,让你求最少经过几次操作,把所有的数变成非负数,操作只有一种,变一个负数变成相反数,但是要把左右两边的数加上这个数. 析:由于看他们AC了,时间这么短,就暴力了一下,就AC了... ...

  3. UVALive 7070 The E-pang Palace(暴力)

    实话说这个题就是个暴力,但是有坑,第一次我以为相含是不行的,结果WA,我加上相含以后还WA,我居然把这两个矩形的面积加在一块了吗,应该取大的那一个啊-- 方法就是枚举对角线,为了让自己不蒙圈,我写了一 ...

  4. UVALive 2145 Lost in Space(暴力)

    题目并不难,就是暴力,需要注意一下输出形式和精度. #include<iostream> #include<cstdio> #include<cmath> usin ...

  5. UVALive 6862 Triples (找规律 暴力)

    Triples 题目链接: http://acm.hust.edu.cn/vjudge/contest/130303#problem/H Description http://7xjob4.com1. ...

  6. UVALive 7457 Discrete Logarithm Problem (暴力枚举)

    Discrete Logarithm Problem 题目链接: http://acm.hust.edu.cn/vjudge/contest/127401#problem/D Description ...

  7. UVALive - 6837 Kruskal+一点性质(暴力枚举)

    ICPC (Isles of Coral Park City) consist of several beautiful islands. The citizens requested constru ...

  8. B. Math Show 暴力 C - Four Segments

    B. Math Show 这个题目直接暴力,还是有点难想,我没有想出来,有点思维. #include <cstdio> #include <cstdlib> #include ...

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

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

随机推荐

  1. perl基本语法

    标量 标量是 Perl 中最简单的数据类型.大多数的标量是数字(如 255 或 3.25e20)或者字符串(如 hello或者盖茨堡地址). 数字 perl中所有数字内部的格式都是双精度浮点数. 浮点 ...

  2. 各浏览器各版本User-agent汇总 欢迎补充

    Internet Explorer Internet Explorer 5 Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; WOW64; Trident/ ...

  3. UVa 11859 (Nim) Division Game

    把每一行m个数所有的素因子看做一堆,就把问题转化为n堆的Nim游戏. 然后预处理一下10000以内每个数素因数的个数,再根据书上的Bouton定理,计算一下n行素因数个数的异或和. 为0是先手必败局面 ...

  4. android和ios流媒体库推荐

    1基本信息编辑 Vitamio是一款 Android 与 iOS 平台上的全能多媒体开发框架,全面支持硬件解码与 GPU 渲染.从2011年8月上线到2014年1月,Vitamio 凭借其简洁易用的 ...

  5. 调试WEB APP多设备浏览器(转)

      方法:adobe shadow  \ opera远程调试\ weinre adobe shadow: 我们经常使用Firefox的firebug或者Chrome的开发人员工具进行Web调试页面,J ...

  6. ECSHOP - 二次开发指南---购物车篇

    第一个问题 保存用户购物车数据ECSHOP的购物车数据,是以Session 方式存储在数据库里,并在Session结束后 ,Distroy 掉,解决方法是: 1.购物车内容读取方式. 更改登陆后购物车 ...

  7. 【转】正确理解PHP程序编译时的错误信息

    我们编写程序时,无论怎样小心谨慎,犯错总是在所难免的.这些错误通常会迷惑PHP编译器.如果开发人员无法了解编译器报错信息的含义,那么这些错误信息不仅毫无用处,还会常常让人感到沮丧. 编译PHP脚本时, ...

  8. hihocoder 1228 Mission Impossible 6

    题意:一个模拟……大概就是模拟一个编辑文档的过程……具体的还是读题吧…… 解法:刚开场就发现的一个模拟……果断敲起来…… 要注意几点与实际编辑过程不同: 1.当用C操作标记一段字符后,只有D会改变这段 ...

  9. [Everyday Mathematics]20150202

    设 $f:\bbR^2\to \bbR$ 为连续函数, 且满足条件 $$\bex f(x+1,y)=f(x,y+1)=f(x,y),\quad\forall\ (x,y)\in \bbR^2. \ee ...

  10. SQL数据库面试题以及答案

    Student(stuId,stuName,stuAge,stuSex) 学生表 stuId:学号:stuName:学生姓名:stuAge:学生年龄:stuSex:学生性别 Course(course ...