思路:

直接状态压缩暴力枚举

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#define Maxn 30
#define inf 10000000
using namespace std;
int ans,n,m;
int c,d;
int map[Maxn][Maxn];
int lis[Maxn],node[Maxn];
int val[<<],sum[<<];
int main()
{
int i,j;
while(scanf("%d%d",&n,&m),n||m){
memset(val,,sizeof(val));
memset(sum,,sizeof(sum));
c=,d=;
for(i=;i<=n;i++)
scanf("%d",&node[i]);
memset(map,,sizeof(map));
for(i=;i<=n;i++){
for(j=;j<=n;j++){
scanf("%d",&map[i][j]);
}
}
int N=<<n;
N-=;
int cnt=;
val[]=;
for(i=;i<=n;i++)
val[<<i]=;
for(i=;i<=N;i++){
cnt=;
for(j=;j<n;j++){
if(i&(<<j)) lis[++cnt]=j+,sum[i]+=node[j+];
}
if(cnt>m) continue;
if(cnt==m)
{
int a=val[i],b=sum[i];
if(a*d<c*b){
ans=i;
c=a;
d=b;
}
}
int temp;
for(j=;j<n;j++){
if(((<<j)&i)==){
temp=inf;
for(int k=;k<=cnt;k++){
temp=min(temp,map[j+][lis[k]]);
}
val[i|(<<j)]=min(val[i]+temp,val[i|(<<j)]);
}
}
}
int num=;
for(j=;j<n;j++)
if((<<j)&ans){
printf("%d",j+);
if(num!=m)
printf(" ");
num++;
}
printf("\n");
}
return ;
}

hdu 2489 最小生成树状态压缩枚举的更多相关文章

  1. hdu 4033 状态压缩枚举

    /* 看别人的的思路 搜索搜不出来我太挫了 状态压缩枚举+好的位置 */ #include<stdio.h> #include<string.h> #define N 20 i ...

  2. hdu 5724 SG+状态压缩

    Chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  3. codeforces B - Preparing Olympiad(dfs或者状态压缩枚举)

    B. Preparing Olympiad You have n problems. You have estimated the difficulty of the i-th one as inte ...

  4. hdu 5094 Maze 状态压缩dp+广搜

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092176.html 题目链接:hdu 5094 Maze 状态压缩dp+广搜 使用广度优先 ...

  5. UVA 1508 - Equipment 状态压缩 枚举子集 dfs

    UVA 1508 - Equipment 状态压缩 枚举子集 dfs ACM 题目地址:option=com_onlinejudge&Itemid=8&category=457& ...

  6. 状态压缩+枚举 POJ 3279 Fliptile

    题目传送门 /* 题意:问最少翻转几次使得棋子都变白,输出翻转的位置 状态压缩+枚举:和之前UVA_11464差不多,枚举第一行,可以从上一行的状态知道当前是否必须翻转 */ #include < ...

  7. 状态压缩+枚举 UVA 11464 Even Parity

    题目传送门 /* 题意:求最少改变多少个0成1,使得每一个元素四周的和为偶数 状态压缩+枚举:枚举第一行的所有可能(1<<n),下一行完全能够由上一行递推出来,b数组保存该位置需要填什么 ...

  8. POJ 1873 UVA 811 The Fortified Forest (凸包 + 状态压缩枚举)

    题目链接:UVA 811 Description Once upon a time, in a faraway land, there lived a king. This king owned a ...

  9. 洛谷P1036 选数 题解 简单搜索/简单状态压缩枚举

    题目链接:https://www.luogu.com.cn/problem/P1036 题目描述 已知 \(n\) 个整数 \(x_1,x_2,-,x_n\) ,以及 \(1\) 个整数 \(k(k& ...

随机推荐

  1. 《Spring3.0就这么简单》第1章快速入门

    问题 [如何将jsp中传递到HttpServletRequest的参数,自动装配到Java对象中] [成功] public void setUsernAme(String username) < ...

  2. js 基于函数伪造的方式实现继承

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  3. PostgreSQL中使用枚举类型

    https://wiki.postgresql.org/wiki/Enum 建立enum: pgsql=# CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy' ...

  4. 【剑指offer】顺时针打印矩阵

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/26053049 剑指offer上的第20题,九度OJ上測试通过. 题目描写叙述: 输入一个矩 ...

  5. Response.Redirect 打开新窗体的两种方法

    普通情况下,Response.Redirect 方法是在server端进行转向,因此,除非使用 Response.Write("<script>window.location=' ...

  6. UVALive 4221 Walk in the Park 扫描线

    Walk in the Park 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemi ...

  7. SGU 538. Emoticons 水题

    538. Emoticons 题目连接: http://acm.sgu.ru/problem.php?contest=0&problem=538 Description A berland n ...

  8. Codeforces Round #338 (Div. 2) C. Running Track dp

    C. Running Track 题目连接: http://www.codeforces.com/contest/615/problem/C Description A boy named Ayrat ...

  9. ACM-经典DP之Monkey and Banana——hdu1069

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...

  10. Gtest源码剖析:1.实现一个超级简单的测试框架xtest

    下面的代码模仿gtest实现,主要说明了以下两点: ASSERT_* 和 EXPECT_*系列断言的原理和作用. gtest是怎样通过宏自动注册测试代码让其自动运行的. #include <io ...