Aizu 2300 Calender Colors dfs
原题链接: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的更多相关文章
- Aizu 2300 Calender Colors(暴力)
状压以后,直接暴力枚举,2^20约等于1e6,而且满足bitcount = m的状态很少. #include<bits/stdc++.h> using namespace std; +; ...
- Aizu 2306 Rabbit Party DFS
Rabbit Party Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view. ...
- Aizu 2309 Sleeping Time DFS
Sleeping Time Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...
- Aizu - 2306 Rabbit Party (DFS图论)
G. Rabbit Party Time Limit: 5000ms Case Time Limit: 5000ms Memory Limit: 65536KB 64-bit integer IO f ...
- 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 ...
- Aizu 0033 Ball(dfs,贪心)
日文题面...题意:是把一连串的有编号的球往左或者往右边放.问能不能两边都升序. 记录左边和右边最上面的球编号大小,没有就-1,dfs往能放的上面放. #include<bits/stdc++. ...
- Aizu - 2305 Beautiful Currency (二分 + DFS遍历)
F. Beautiful Currency Time Limit: 5000ms Case Time Limit: 5000ms Memory Limit: 65536KB 64-bit intege ...
- 【Aizu - 0525】Osenbei (dfs)
-->Osenbei 直接写中文了 Descriptions: 给出n行m列的0.1矩阵,每次操作可以将任意一行或一列反转,即这一行或一列中0变为1,1变为0.问通过任意多次这样的变换,最多可以 ...
- Aizu 0531 "Paint Color" (坐标离散化+DFS or BFS)
传送门 题目描述: 为了宣传信息竞赛,要在长方形的三合板上喷油漆来制作招牌. 三合板上不需要涂色的部分预先贴好了护板. 被护板隔开的区域要涂上不同的颜色,比如上图就应该涂上5种颜色. 请编写一个程序计 ...
随机推荐
- JVM垃圾回收原理
原文地址:http://chenchendefeng.iteye.com/blog/455883 一.相关概念 基本回收算法 1. 引用计数(Reference Counting) 比较古老的回收算法 ...
- Java之基于Apache jar包的FTPClient上传
首先,准备工作: http://pan.baidu.com/s/1dD1Utwt 从以上链接下载Apache的jar包,并将其复制到工程的WEB-INF下的lib包里,在此,准备工作就已经完成了. 具 ...
- 【Triangle 】cpp
题目: Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjace ...
- Kafka 配置参数
Broker Configs Property Default Description broker.id 每个broker都可以用一个唯一的非负整数id进行标识:这个id可以作为broker的 ...
- CSU-2046: sequence
CSU-2046: sequence Description 给出一个长度为N的正整数序列a,你有两种变换操作: 1.把数列中的某个数乘 2. 2.把数列中的所有数减 1. 现在你需要通过最少的变换操 ...
- MFC之HTTP文件上传
BOOL UploadFile(LPCTSTR strURL, LPCTSTR strLocalFileName) { // 如果URL为空或者文件不存在,直接返回 if (strURL == NUL ...
- Spring MVC请求到处理方法注解配置的几种方式
@RequestMapping 这个是最常用的注解,可以配置在类上,也可以配置在方法上,两个一起作用组成方法能够响应的请求路径,举例如下 package org.zln.myWeb.controlle ...
- PIC单片机之时钟设置
PIC单片机之时钟设置 http://blog.csdn.net/superanters/article/details/8541650 内部时钟和外部时钟? PIC单片机有许多型号可以设置成 用外部 ...
- Activity启动创建 (AcitivtyManageService,ActivityThread,Activity)
ActivityThead,ActivityManagerService,Activity <<Android内核剖析>>中有一章节专门介绍 Activity框架和管理结构A ...
- bzoj 2503 相框 分类讨论
题目大意:给定一张无向图,每次可以进行以下两种操作: 1.将一个点分裂成一些点,原先这个点连接的每条边任选一个新点进行连接 2.将两个度数为1的点合并为1个点 求将这个图变成一个环的最小操作次数 我们 ...