hashmap判重大法好

 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
#define MOD 1000000007
const int INF=0x3f3f3f3f;
const double eps=1e-;
typedef long long ll;
#define cl(a) memset(a,0,sizeof(a))
#define ts printf("*****\n");
const int MAXN=;
int n,m,tt;
int sum=,a[MAXN];
const int HASH = ;
struct HASHMAP
{
int head[HASH],next[HASH],size;
int state[HASH][];
int hash(int a,int b,int c)
{
return (((a*+b)*+c)*)%HASH;  //131
}
void init()
{
size = ;
memset(head,-,sizeof(head));
}
int insert(int a,int b,int c)
{
int h = hash(a,b,c);
for(int i = head[h]; i != -;i = next[i])
if(a == state[i][]&&b == state[i][]&&c == state[i][])
{
return ;
}
state[size][]=a,state[size][]=b,state[size][]=c;
next[size] = head[h];
head[h] = size++;
return ;
}
} H1;
bool check(int a1,int a2,int a3)
{
if(a1+a2>a3&&a1+a3>a2&&a2+a3>a1) return ;
else return ;
}
void dfs(int a1,int a2,int a3,int pos)
{
if(a3>sum/) return;
if(pos>=n)
{
if(a1==||a2==||a3==) return;
if(check(a1,a2,a3)&&a1>=a2&&a2>=a3)
{
H1.insert(a1,a2,a3);
}
return;
}
dfs(a1+a[pos],a2,a3,pos+);
dfs(a1,a2+a[pos],a3,pos+);
dfs(a1,a2,a3+a[pos],pos+);
} int main()
{
int i,j,k,ca=;
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif
scanf("%d",&tt);
while(tt--)
{
H1.init();
sum=;
scanf("%d",&n);
for(i=;i<n;i++) scanf("%d",a+i),sum+=a[i];
dfs(,,,);
printf("%d\n",H1.size);
}
}

hdu 4277 2012长春赛区网络赛 dfs+hashmap ***的更多相关文章

  1. hdu 4272 2012长春赛区网络赛 dfs暴力 ***

    总是T,以为要剪枝,后来发现加个map就行了 #include<cstdio> #include<iostream> #include<algorithm> #in ...

  2. hdu 4273 2012长春赛区网络赛 三维凸包中心到最近面距离 ***

    新模板 /* HDU 4273 Rescue 给一个三维凸包,求重心到表面的最短距离 模板题:三维凸包+多边形重心+点面距离 */ #include<stdio.h> #include&l ...

  3. hdu 4274 2012长春赛区网络赛 树形dp ***

    设定每个节点的上限和下限,之后向上更新,判断是否出现矛盾 #include<cstdio> #include<iostream> #include<algorithm&g ...

  4. hdu 4741 2013杭州赛区网络赛 dfs ***

    起点忘记录了,一直wa 代码写的很整齐,看着很爽 #include<cstdio> #include<iostream> #include<algorithm> # ...

  5. hdu 4412 2012杭州赛区网络赛 期望

    虽然dp方程很好写,就是这个期望不知道怎么求,昨晚的BC也是 题目问题抽象之后为:在一个x坐标轴上有N个点,每个点上有一个概率值,可以修M个工作站, 求怎样安排这M个工作站的位置,使得这N个点都走到工 ...

  6. hdu 4411 2012杭州赛区网络赛 最小费用最大流 ***

    题意: 有 n+1 个城市编号 0..n,有 m 条无向边,在 0 城市有个警察总部,最多可以派出 k 个逮捕队伍,在1..n 每个城市有一个犯罪团伙,          每个逮捕队伍在每个城市可以选 ...

  7. hdu 4293 2012成都赛区网络赛 dp ****

    题意:有n个人,可任意分成若干组,然后每个人个各提供一个信息,表示他们组前面有多少人,后面有多少人.问最多有多少个信息是不冲突的. 将n个人看成一组区间,然后每个人的信息可以表示为该人所在组的区间,然 ...

  8. hdu 4291 2012成都赛区网络赛 矩阵快速幂 ***

    分析:假设g(g(g(n)))=g(x),x可能非常大,但是由于mod 10^9+7,所以可以求出x的循环节 求出x的循环节后,假设g(g(g(n)))=g(x)=g(g(y)),即x=g(y),y也 ...

  9. hdu 4278 2012天津赛区网络赛 数学 *

    8进制转为10进制 #include<cstdio> #include<iostream> #include<algorithm> #include<cstr ...

随机推荐

  1. IP转换成LONG 的 问题

    如何将四个字段以点分开的IP网络址协议地址转换成整数呢?PHP里有这么一个函数ip2long.比如 <?php echo ip2long("10.2.1.3"); ?> ...

  2. shell脚本实现拷贝大文件显示百分比的代码分享

    #!/bin/sh strace -q -eread cp -- "${1}" "${2}" 2>&1 \| awk '{    count += ...

  3. Wince下sqlce数据库开发(二)

    上次写到使用数据绑定的方法测试本地sqlce数据库,这次使用访问SQL Server的方法访问sqlce,你会发现他们是如此的相似... 参考资料:http://www.cnblogs.com/rai ...

  4. 多线程BackroundWorker 使用

    参考文章:http://www.cnblogs.com/inforasc/archive/2009/10/12/1582110.html using System; using System.Coll ...

  5. 7. javacript高级程序设计- 函数表达式

    1. 函数表达式 1.1 函数定义 函数定义的方式有两种:一种是函数声明,另一种就是函数表达式. (1). 函数声明:函数声明的重要特征就是函数声明提示,函数声明会在函数执行前执行 function ...

  6. 为什么使用<!DOCTYPE HTML>

    不管是刚接触前端,还是你已经"精通"web前端开发的内容,你应该知道在你写html的时候需要定义文档类型:你知道如果没有它,浏览器在渲染页面的时候会使用怪异模式:你知道各个浏览器在 ...

  7. IOS - 键盘处理

    iOS 发布了很多关于屏幕上键盘的通知.下面列出了这些通知的简要解释: UIKeyboardWillShowNotification 当键盘即将要显示的时候将会发出这个通知.这个通知包含了用户信息库, ...

  8. 2048控制台程序:一份帝国理工C++作业

    #include <fstream> #include <vector> #include <iostream> #include <string> u ...

  9. August 12th 2016 Week 33rd Friday

    Everything is good in its season. 万物逢时皆美好. Every dog has its day. You are not in your best condition ...

  10. CUDA中并行规约(Parallel Reduction)的优化

    转自: http://hackecho.com/2013/04/cuda-parallel-reduction/ Parallel Reduction是NVIDIA-CUDA自带的例子,也几乎是所有C ...