UVaLive 6623 Battle for Silver (最大值,暴力)
题意:给定一个图,让你找一个最大的子图,在这个子图中任何两点都有边相连,并且边不交叉,求这样子图中权值最大的是多少。
析:首先要知道的是,要想不交叉,那么最大的子图就是四个点,否则一定交叉,然后就暴力就好,数据水,不会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 (最大值,暴力)的更多相关文章
- CDOJ 889 Battle for Silver
Battle for Silver Time Limit: 2999/999MS (Java/Others) Memory Limit: 65432/65432KB (Java/Others) ...
- UVaLive 6855 Banks (水题,暴力)
题意:给定 n 个数,让你求最少经过几次操作,把所有的数变成非负数,操作只有一种,变一个负数变成相反数,但是要把左右两边的数加上这个数. 析:由于看他们AC了,时间这么短,就暴力了一下,就AC了... ...
- UVALive 7070 The E-pang Palace(暴力)
实话说这个题就是个暴力,但是有坑,第一次我以为相含是不行的,结果WA,我加上相含以后还WA,我居然把这两个矩形的面积加在一块了吗,应该取大的那一个啊-- 方法就是枚举对角线,为了让自己不蒙圈,我写了一 ...
- UVALive 2145 Lost in Space(暴力)
题目并不难,就是暴力,需要注意一下输出形式和精度. #include<iostream> #include<cstdio> #include<cmath> usin ...
- UVALive 6862 Triples (找规律 暴力)
Triples 题目链接: http://acm.hust.edu.cn/vjudge/contest/130303#problem/H Description http://7xjob4.com1. ...
- UVALive 7457 Discrete Logarithm Problem (暴力枚举)
Discrete Logarithm Problem 题目链接: http://acm.hust.edu.cn/vjudge/contest/127401#problem/D Description ...
- UVALive - 6837 Kruskal+一点性质(暴力枚举)
ICPC (Isles of Coral Park City) consist of several beautiful islands. The citizens requested constru ...
- B. Math Show 暴力 C - Four Segments
B. Math Show 这个题目直接暴力,还是有点难想,我没有想出来,有点思维. #include <cstdio> #include <cstdlib> #include ...
- 2014 UESTC 暑前集训队内赛(3) 部分解题报告
B.Battle for Silver 定理:完全图Kn是平面图当且仅当顶点数n<=4. 枚举所有完全图K1,K2,K3,K4,找出最大总权重. 代码: #include <iostrea ...
随机推荐
- HDU 4864 (2014 Multi-University Training Contest 1 )
考试时,想到了一个很类似的方法,但是总是差那么点,就是这么点,需要不断的努力啊!!! 题解: 基本思想是贪心. 对于价值c=500*xi+2*yi,yi最大影响100*2<500,所以就是求xi ...
- 宏UT_LIST_ADD_FIRST
/*******************************************************************//** Adds the node as the first ...
- bzoj1266: [AHOI2006]上学路线route
最短路+最小割 首先如何使最短路变长?就是要每一条最短路都割一条边. 我们求出每个点到点1和点n的距离,就可以知道哪些边在最短路上(一开始没有想到求到0和n的距离,想用floyd,但是n=500,怕超 ...
- BZOJ_1029_[JSOI2007]_建筑抢修_(贪心+优先队列)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1029 \(n\)个任务需要完成,给出每个任务所需时间\(t_1\)与deadline\(t_2 ...
- Java知识点:琐碎知识点(2)
49个关键字一览 abstract default if private this boolean do implements protected throw break double import ...
- Android Dialog使用举例
在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,在我们使用Android的过程中,我归纳了一 ...
- linux - 开机启动thunderbird、chromium
cd ~/.config/autostart/(没有autostart,自己 mkdir autostart) vim thunderbird.desktop,输入以下: [Desktop Entry ...
- Json::Value使用心得
Json::Value 是sourceforge开源项目jsoncpp的数据对象,用来处理json数据 下载 1.打印Json数据 Json::Value jv; Json::FastWriter ...
- hadoop1.2.1 伪分布式配置
主要配置 core-site.xml hdfs-site.xml mapred-site.xml
- leetcode—Swap Nodes in Pairs
1.题目描述 Given a linked list, swap every two adjacent nodes and return its head. For example, Given ...