hdu 4277 2012长春赛区网络赛 dfs+hashmap ***
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 ***的更多相关文章
- hdu 4272 2012长春赛区网络赛 dfs暴力 ***
总是T,以为要剪枝,后来发现加个map就行了 #include<cstdio> #include<iostream> #include<algorithm> #in ...
- hdu 4273 2012长春赛区网络赛 三维凸包中心到最近面距离 ***
新模板 /* HDU 4273 Rescue 给一个三维凸包,求重心到表面的最短距离 模板题:三维凸包+多边形重心+点面距离 */ #include<stdio.h> #include&l ...
- hdu 4274 2012长春赛区网络赛 树形dp ***
设定每个节点的上限和下限,之后向上更新,判断是否出现矛盾 #include<cstdio> #include<iostream> #include<algorithm&g ...
- hdu 4741 2013杭州赛区网络赛 dfs ***
起点忘记录了,一直wa 代码写的很整齐,看着很爽 #include<cstdio> #include<iostream> #include<algorithm> # ...
- hdu 4412 2012杭州赛区网络赛 期望
虽然dp方程很好写,就是这个期望不知道怎么求,昨晚的BC也是 题目问题抽象之后为:在一个x坐标轴上有N个点,每个点上有一个概率值,可以修M个工作站, 求怎样安排这M个工作站的位置,使得这N个点都走到工 ...
- hdu 4411 2012杭州赛区网络赛 最小费用最大流 ***
题意: 有 n+1 个城市编号 0..n,有 m 条无向边,在 0 城市有个警察总部,最多可以派出 k 个逮捕队伍,在1..n 每个城市有一个犯罪团伙, 每个逮捕队伍在每个城市可以选 ...
- hdu 4293 2012成都赛区网络赛 dp ****
题意:有n个人,可任意分成若干组,然后每个人个各提供一个信息,表示他们组前面有多少人,后面有多少人.问最多有多少个信息是不冲突的. 将n个人看成一组区间,然后每个人的信息可以表示为该人所在组的区间,然 ...
- 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也 ...
- hdu 4278 2012天津赛区网络赛 数学 *
8进制转为10进制 #include<cstdio> #include<iostream> #include<algorithm> #include<cstr ...
随机推荐
- 转:sql之left join、right join、inner join的区别
left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录inner join(等值连接) 只 ...
- 保存字符串到手机SDcard为txt文件
try { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { File sdCardDir ...
- 【架构】Google的大规模集群管理工具Borg
参考资料: http://www.cnblogs.com/YaoDD/p/5374393.html http://www.cnblogs.com/YaoDD/p/5351589.html
- 基于“事件”驱动的领域驱动设计(DDD)框架分析
摘抄自 从去年10月份开始,学了几个月的领域驱动设计(Domain Driven Design,简称DDD).主要是学习领域驱动设计之父Eric Evans的名著:<Domain-driven ...
- sizeof和strlen的区别
一.sizeof sizeof(...)是运算符,而不是一个函数. sizeof操作符的结果类型是size_t,在头文件中typedef为unsigned int,其值在编译时即计算好了, ...
- 通过nsenter连接docker容器
通常连接Docker容器并与其进行交互有四种方法.详情见:https://github.com/berresch/Docker-Enter-Demo,下面摘录nsenter连接的方式. 查看是否安装n ...
- google API 点连线
这个是模拟的数据,用于测试,为了方便学习 弹出框信息都是固定的,以及操作都不是写的循环,实际开发用 setInterval 或者for 以减少冗余. <!DOCTYPE html> < ...
- javascript 事件委托,jq,js模拟事件
<!DOCTYPE> <html> <head> <title></title> <script src="Scripts/ ...
- eclipse 工作环境配置
1.更换编辑颜色, http://eclipse-color-theme.github.io/update/ 下载离线安装包,解压缩 eclipse-color-theme-update-site\u ...
- WinAPI: ShellExecute - 打开外部程序或文件
WinAPI: ShellExecute - 打开外部程序或文件 ShellExecute( hWnd: HWND; {指定父窗口句柄} Operation: PChar; { ...