zoukankan      html  css  js  c++  java
  • Aizu 2300 Calender Colors(暴力)

    状压以后,直接暴力枚举,2^20约等于1e6,而且满足bitcount = m的状态很少。

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 20+1;
    double x[maxn],y[maxn],z[maxn];
    double d[maxn][maxn];
    double squ(double x) { return x*x; }
    double dist(int i,int j) { return squ(x[i]-x[j])+squ(y[i]-y[j])+squ(z[i]-z[j]); }
    
    //#define LOCAL
    int main()
    {
    #ifdef LOCAL
        freopen("in.txt","r",stdin);
    #endif
        int n,m; scanf("%d%d",&n,&m);
        for(int i = 0; i < n; i++){
            scanf("%lf%lf%lf",x+i,y+i,z+i);
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < i; j++){
                d[i][j] = dist(i,j);
            }
        }
        double ans = 0;
        int vc[maxn];
        for(int S = (1<<n)-1; S>=0; S--){
            int c = 0;
            for(int i = 0; i < n; i++){
                if(S>>i&1) vc[c++] = i;
            }
            if(c == m){
                double sum = 0;
                for(int i = 0; i < c; i++){
                    int a = vc[i];
                    for(int j = 0; j < i; j++){
                        sum += d[a][vc[j]];
                    }
                }
                ans = max(ans,sum);
            }
        }
        printf("%lf
    ",ans);
        return 0;
    }
  • 相关阅读:
    452.用最少数量的箭引爆气球
    134.加油站
    Javascript
    spring-JDBC模板
    AOP注解方式ApsectJ开发
    AOP通知类型
    AOP的使用
    AOP相关术语
    AOP
    IOC注解详解
  • 原文地址:https://www.cnblogs.com/jerryRey/p/4851297.html
Copyright © 2011-2022 走看看