原题链接: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. FreeMarker的<#if></#if>标签

    <#if target??> xxxx </#if> 上面这段代码判断target??是否为null,如果不为null时才可以执行if里面的内容,为null时则不进到 if里面 ...

  2. Python中str、list、numpy分片操作

    在Python里,像字符串(str).列表(list).元组(tupple)和这类序列类型都支持切片操作 对对象切片,s是一个字符串,可以通过类似数组索引的方式获取字符串中的字符,同时也可以用s[a: ...

  3. Careercup - Microsoft面试题 - 5188169901277184

    2014-05-12 06:12 题目链接 原题: Write a function to retrieve the number of a occurrences of a substring(ev ...

  4. adb命令模拟按键事件

    //这条命令相当于按了设备的Backkey键 adb shell input keyevent 4 //可以解锁屏幕 adb shell input keyevent  82 //在屏幕上做划屏操作, ...

  5. Leetcode 532.数组中的K-diff数对

    数组中的K-diff数对 给定一个整数数组和一个整数 k, 你需要在数组里找到不同的 k-diff 数对.这里将 k-diff 数对定义为一个整数对 (i, j), 其中 i 和 j 都是数组中的数字 ...

  6. android TranslateAnimation动画执行时的坐标获取。

    android 的Tween动画并不会改变控件的属性值,比如以下测试片段: 定义一个从屏幕右边进入,滚动到屏幕左边消失的一个TranslateAnimation动画: <?xml version ...

  7. java-dispose方法

    今天在编一道JAVA例题时,看到 dispose 这个方法,在程序中是用来关闭一个GUI页面的.这也让我想到了setVisible(false)方法.在网上查了意思,dispose()即释放所有本机屏 ...

  8. jQuery动态显示和隐藏datagrid中的某一列的方法

    在EasyUI中: 1)展示某列的方法:     $('#jgrid').datagrid('showColumn', 'XXX');  -----其中 XXX 是隐藏列的  field 属性值 2) ...

  9. 【bzoj3771】Triple FFT+容斥原理

    题目描述 樵夫的每一把斧头都有一个价值,不同斧头的价值不同.总损失就是丢掉的斧头价值和. 他想对于每个可能的总损失,计算有几种可能的方案. 注意:如果水神拿走了两把斧头a和b,(a,b)和(b,a)视 ...

  10. Pointcut is not well-formed: expecting 'identifier' at character position 0 ^ || Pointcut is not well-formed: expecting ')' at character position 11 ^

    错误提示: 解决方法1:指定execution 在执行目标方法之前指定execution 解决方法2:可能是execution写错了.请仔细检查. 其他——execution参数设置(带问好的可以不配 ...