原题链接:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2300

题意:

给你一个图,让你生成一个完全子图。使得这个子图中每个点的最小边的和最大。。好拗口,但是就是这么回事。。

题解:

就直接dfs就好,搜啊搜啊,就做出来了。

代码:

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#define MAX_N 20
#define MAX_S 1<<20
using namespace std; double dp[MAX_S]; double L[MAX_N],a[MAX_N],b[MAX_N]; int N,M; int getOnes(int s) {
int res = ;
while (s) {
if (s & )res++;
s >>= ;
}
return res;
} bool vis[MAX_S]; double dis(int i,int j) {
return (L[i] - L[j]) * (L[i] - L[j]) + (a[i] - a[j]) * (a[i] - a[j]) + (b[i] - b[j]) * (b[i] - b[j]);
} void dfs(int s) {
for (int i = ; i < N; i++) {
if (( << i) & s)continue;
int t = ( << i) | s;
if (vis[t])continue;
vis[t] = ;
double sum = ;
for (int j = ; j < N; j++)
if (( << j) & s)
sum += dis(i, j);
dp[t] = dp[s] + sum;
dfs(t);
}
} int main() {
scanf("%d%d", &N, &M);
for (int i = ; i < N; i++)
scanf("%lf%lf%lf", &L[i], &a[i], &b[i]);
dfs();
double ans = ;
for (int i = ; i < ( << N); i++)
if (getOnes(i) == M)
ans = max(ans, dp[i]);
printf("%.5f\n", ans);
return ;
}

Aizu 2300 Calender Colors dfs的更多相关文章

  1. Aizu 2300 Calender Colors(暴力)

    状压以后,直接暴力枚举,2^20约等于1e6,而且满足bitcount = m的状态很少. #include<bits/stdc++.h> using namespace std; +; ...

  2. Aizu 2306 Rabbit Party DFS

    Rabbit Party Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view. ...

  3. Aizu 2309 Sleeping Time DFS

    Sleeping Time Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...

  4. Aizu - 2306 Rabbit Party (DFS图论)

    G. Rabbit Party Time Limit: 5000ms Case Time Limit: 5000ms Memory Limit: 65536KB 64-bit integer IO f ...

  5. Aizu 2302 On or Off dfs/贪心

    On or Off Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...

  6. Aizu 0033 Ball(dfs,贪心)

    日文题面...题意:是把一连串的有编号的球往左或者往右边放.问能不能两边都升序. 记录左边和右边最上面的球编号大小,没有就-1,dfs往能放的上面放. #include<bits/stdc++. ...

  7. Aizu - 2305 Beautiful Currency (二分 + DFS遍历)

    F. Beautiful Currency Time Limit: 5000ms Case Time Limit: 5000ms Memory Limit: 65536KB 64-bit intege ...

  8. 【Aizu - 0525】Osenbei (dfs)

    -->Osenbei 直接写中文了 Descriptions: 给出n行m列的0.1矩阵,每次操作可以将任意一行或一列反转,即这一行或一列中0变为1,1变为0.问通过任意多次这样的变换,最多可以 ...

  9. Aizu 0531 "Paint Color" (坐标离散化+DFS or BFS)

    传送门 题目描述: 为了宣传信息竞赛,要在长方形的三合板上喷油漆来制作招牌. 三合板上不需要涂色的部分预先贴好了护板. 被护板隔开的区域要涂上不同的颜色,比如上图就应该涂上5种颜色. 请编写一个程序计 ...

随机推荐

  1. #3 working with data stored in files && securing your application (PART II)

    Security problems is more and more important on the internet today. You can see the problems . This ...

  2. python如何合并两个字典

    我有两个Python字典,如何合并它们呢?update()方法正是你所需要的. >>> x = {'a':1, 'b': 2} >>> y = {'b':10, ' ...

  3. WCF,WebServices,WebApi区别

    http://www.cnblogs.com/hetring/p/4493137.html

  4. 【Letter Combinations of a Phone Number】cpp

    题目: Given a digit string, return all possible letter combinations that the number could represent. A ...

  5. 解决This application failed to start because it could not find or load the Qt platform plugin "windows

    解决方案:所在环境python根目录下qt.conf,重新设置path即可,此类问题通常在目录转移之后出现.

  6. linux命令之grep、cut

    输入: ifconfig eth0 eth0表示主机的第一块网卡. 输出: eth0: flags=<UP,BROADCAST,RUNNING,MULTICAST> mtu inet 19 ...

  7. python 中输入一个字符串,判断这个字符串中有多少个字符、数字、空格、特殊字符

    # -*- coding: utf8 -*- # Author:wxq #python 2.7 #首先定义一个字符串 str1 = raw_input('请输入一个字符:') #初始化字符.数字.空格 ...

  8. 位图 c++ 位图排序

    什么是位图?来自http://www.cnblogs.com/dolphin0520/archive/2011/10/19/2217369.html 位图就是用一个bit来标记某个元素对应的值,键值就 ...

  9. BZOJ3129 [Sdoi2013]方程 【扩展Lucas】

    题目 给定方程 X1+X2+. +Xn=M 我们对第l..N1个变量进行一些限制: Xl < = A X2 < = A2 Xn1 < = An1 我们对第n1 + 1..n1+n2个 ...

  10. BZOJ3295 [Cqoi2011]动态逆序对 【CDQ分治】

    题目 对于序列A,它的逆序对数定义为满足i 输入格式 输入第一行包含两个整数n和m,即初始元素的个数和删除的元素个数.以下n行每行包含一个1到n之间的正整数,即初始排列.以下m行每行一个正整数,依次为 ...