枚举。

看了这个方法:$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. EPROCESS KPROCESS PEB

    EPROCESS KPROCESS PEB <寒江独钓>内核学习笔记(2)     在学习笔记(1)中,我们学习了IRP的数据结构的相关知识,接下来我们继续来学习内核中很重要的另一批数据结 ...

  2. oracle数据库对date字段类型存在空值进行排序的处理方法

    oracle数据库对date字段类型存在空值进行排序的处理方法      oracle 数据库,如果表中有一个字段类型为date,且该字段类型存在空值,并且需要排序,     解决方法为使用oracl ...

  3. 【Lotus Notes】邮件获取

    public class LotusManager { public static int bodyMaxLength, length; public static List<Entity.Lo ...

  4. javascript的笔记

    好久没写东西了,最近有些迷茫(好吧,是借口),也是好久没有接触js的内容了,今天就借此契机,顺便复习下吧. 就看看javascript中的函数四大调用模式和this的关系 1.方法调用模式 当一个函数 ...

  5. C# 编写简易 ASP.NET Web 服务器

    C# 编写简易 ASP.NET Web 服务器 你是否有过这样的需求——想运行 ASP.NET 程序,又不想安装 IIS 或者 Visual Studio?我想如果你经常编写 ASP.NET 程序的话 ...

  6. MingQQ v1.0高仿版开源了,使用WebQQ协议实现了QQ客户端基本的聊天功能...

    MingQQ v1.0高仿版开源了,使用WebQQ协议实现了QQ客户端基本的聊天功能... MingQQ目前支持的功能如下:1.支持普通方式登录.验证码方式登录.注销.保持在线.改变在线状态.2.支持 ...

  7. service structure flowchart [mobile to server via HTTP RESTful API]

    Modern flowchart for mobile, server, and etc.. communication This has something to do with these sou ...

  8. PHP自学之路---雇员管理系统(2)

    这个章节将讲解分层模式对雇员管理系统的系统,首先看下基本的流程图设计: 下面是具体的代码: 1.login.php(参照上节) 2.loginProcess.php <?php /** * * ...

  9. 维吉尼亚密码java代码实现根据密钥长度计算IC值过程

    package cn.longxuzi; import java.util.Scanner; import org.junit.Test; public class ICUtils { /** * @ ...

  10. 快速上手微信小程序-快递100

    2007 年 1 月 9 日,乔布斯在旧金山莫斯科尼会展中心发布了首款 iPhone,而在十年后的 1 月 9 日,微信小程序正式上线.张小龙以这样的形式,向乔布斯致敬. 小程序在哪里? 小程序功能模 ...