枚举。

看了这个方法:$http://www.cppblog.com/shiming413/archive/2008/12/21/29671.html$

将数字归类的地方不能用$vector$,会超时。$vector$换成数组就可以过,类似于邻接表。

因为题目给出的$16$个数字都是不同的,所以时间复杂度相对还比较低。

下面这组数据是极限数据,我的跑了$3800$$ms$。但测试数据中不会出现这样的数据。

$5$ $5$ $5$ $5$ $5$ $5$ $5$ $5$ $5$ $5$ $5$ $5$ $5$ $5$ $5$

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar(); x = ;while(!isdigit(c)) c = getchar();
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
} int a[],b[];
LL h[(<<)+]; struct X
{
int b, nx;
}e[];
int g[],k; void add(int a,int b)
{
e[k].b=b; e[k].nx=g[a]; g[a]=k++;
} int main()
{
int cas=;
while(~scanf("%d",&a[]))
{
if(a[]==) break;
for(int i=;i<=;i++) scanf("%d",&a[i]); k=; memset(g,-,sizeof g);
for(int i=;i<(<<);i++)
{
int t=i,cnt=;
for(int j=;j<;j++) if(i&(<<j)) b[cnt++]=j;
if(cnt!=) continue;
sort(b,b+);
do
{
add(*a[b[]]+*a[b[]]+*a[b[]]+*a[b[]],i);
}while(next_permutation(b,b+));
} memset(h,,sizeof h); for(int i=;i<=;i++)
{
for(int j=g[i];j!=-;j=e[j].nx)
{
for(int d=e[j].nx;d!=-;d=e[d].nx)
{
int f1=e[d].b,f2=e[j].b;
if(f1&f2) continue;
h[f1^f2]++;
}
}
} LL ans=;
for(int i=;i<(<<);i++)
{
int t=i,cnt=;
for(int j=;j<;j++) if(i&(<<j)) cnt++;
if(cnt!=) continue;
ans=ans+h[i]*h[(<<)--i];
}
printf("Case %d: %lld\n",cas++,ans/);
}
return ;
}

POJ 3139 Balancing the Scale的更多相关文章

  1. POJ.1655 Balancing Act POJ.3107 Godfather(树的重心)

    关于树的重心:百度百科 有关博客:http://blog.csdn.net/acdreamers/article/details/16905653 1.Balancing Act To POJ.165 ...

  2. poj 1655 Balancing Act 求树的重心【树形dp】

    poj 1655 Balancing Act 题意:求树的重心且编号数最小 一棵树的重心是指一个结点u,去掉它后剩下的子树结点数最少. (图片来源: PatrickZhou 感谢博主) 看上面的图就好 ...

  3. POJ 1655 Balancing Act【树的重心】

    Balancing Act Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14251   Accepted: 6027 De ...

  4. POJ 1655.Balancing Act 树形dp 树的重心

    Balancing Act Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14550   Accepted: 6173 De ...

  5. POJ 1655.Balancing Act-树的重心(DFS) 模板(vector存图)

    Balancing Act Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17497   Accepted: 7398 De ...

  6. poj 1655 Balancing Act(找树的重心)

    Balancing Act POJ - 1655 题意:给定一棵树,求树的重心的编号以及重心删除后得到的最大子树的节点个数size,如果size相同就选取编号最小的. /* 找树的重心可以用树形dp或 ...

  7. POJ 1655 Balancing Act 树的重心

    Balancing Act   Description Consider a tree T with N (1 <= N <= 20,000) nodes numbered 1...N. ...

  8. POJ 1655 Balancing Act (求树的重心)

    求树的重心,直接当模板吧.先看POJ题目就知道重心什么意思了... 重心:删除该节点后最大连通块的节点数目最小 #include<cstdio> #include<cstring&g ...

  9. POJ 1655 Balancing Act&&POJ 3107 Godfather(树的重心)

    树的重心的定义是: 一个点的所有子树中节点数最大的子树节点数最小. 这句话可能说起来比较绕,但是其实想想他的字面意思也就是找到最平衡的那个点. POJ 1655 题目大意: 直接给你一棵树,让你求树的 ...

随机推荐

  1. let和const关键词

    ECMAScript 6中的let和const关键词 2013-11-28 21:46 by BarretLee, 21 阅读, 0 评论, 收藏, 编辑 ECMAScript 6中多了两个定义变量的 ...

  2. UVA 408 (13.07.28)

     Uniform Generator  Computer simulations often require random numbers. One way to generatepseudo-ran ...

  3. CloudFormation

    亚马逊云服务之CloudFormation   亚马逊的Web Service其实包含了一套云服务.云服务主要分为三种: IaaS: Infrastructure as a service,基础设施即 ...

  4. 在html中使用javascript显示本地图片的

    <html> <head> <script type="text/javascript"> function getFullPath(obj){ ...

  5. jQuery Validation让验证变得如此容易(一)

    一.官网下载jquery,和jquery validation plugin http://jqueryvalidation.org/ 二.引入文件 <script src="js/j ...

  6. 多平台Client TCP通讯组件

    Beetle.NetPackage是一个多平台Client Socket TCP通讯组件(Apache License 2.0),组件制统一的对象协议制定规则,可以灵活方便地通过对象来描述TCP通讯交 ...

  7. 一步一步深入spring(6)--使用基于XML配置的spring实现的AOP

    上节我们提到了使用基于注解实现的AOP,这节我们将用基于xml配置的方式来实现的AOP. 1.首先建立一个类,作为切面类,这个类主要用来实现注解中各种通知要实现的方法. package com.yan ...

  8. lucene 查询+分页+排序

    lucene 查询+分页+排序 1.定义一个工厂类 LuceneFactory 1 import java.io.IOException; 2 3 import org.apache.lucene.a ...

  9. 快速构建C++项目工具Scons,结合Editplus搭建开发环境

    Windows下C++开发工具用的最多的非VS莫属了(当然也有很多比如eclipse,Qt等等),便捷的项目构建向导,再加上强大的VC助手,使得开发和调试得心应手.并不是说vc就没有缺点,相反缺点也不 ...

  10. ERROR 1130: Host xxx is not allowed to connect to this MySQL server

    在使用MySQL-Front连接mysql的时候发生的这个错误 ERROR 1130: Host xxx is not allowed to connect to this MySQL server ...