【HDU-4277】USACO ORZ(暴搜)

直接dfs暴力,不需要减枝,
利用set进行判断重复,hash一下,转化成一个longlong的数保存就好了。

#include<cstdio>
#include<set>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXD 20 + 5
typedef long long LL;
int n;
LL array[MAXD];
set<LL>vis;
LL ans;
void dfs(LL a,LL b,LL c,int cur){
    if(cur == n){
        if(a >= b && b >= c){
            if(a + b > c && a + c > b && b + c > a && a && b && c){
                LL t = c * 100000001 + b * 10001 + a;
                if(!vis.count(t)){
                    ans ++ ;
                    vis.insert(t);
                }
            }
        }
        return ;
    }
    dfs(a + array[cur],b,c,cur + 1);
    dfs(a,b + array[cur],c,cur + 1);
    dfs(a,b,c + array[cur],cur + 1);
    return ;
}
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        vis.clear();
        for(int i = 0 ; i < n ; i++)
            scanf("%I64d",&array[i]);
        ans = 0;
        dfs(0,0,0,0);
        printf("%I64d\n",ans);
    }
    return 0;
}
时间: 2024-10-31 15:03:31

【HDU-4277】USACO ORZ(暴搜)的相关文章

HDU 4277 USACO ORZ(暴力+双向枚举)

USACO ORZ Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3809    Accepted Submission(s): 1264 Problem Description Like everyone, cows enjoy variety. Their current fancy is new shapes for pastu

hdu 4277 USACO ORZ DFS

USACO ORZ Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3581    Accepted Submission(s): 1196 Problem Description Like everyone, cows enjoy variety. Their current fancy is new shapes for pastur

hdu 4277 USACO ORZ(dfs+剪枝)

Problem Description Like everyone, cows enjoy variety. Their current fancy is new shapes for pastures. The old rectangular shapes are out of favor; new geometries are the favorite.I. M. Hei, the lead cow pasture architect, is in charge of creating a

hdu 5305 Friends 【暴搜】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5305 题意:给一个无向图 , 每条边可以是online边也可以是offline边,问 有多少种方法使得每个节点的online边和offline边一样多 解法:暴搜.记录每个点连接的边数,奇数的直接不可能,偶数的分成两个数组,c1[i]表示i的在线朋友数,c2[i]表示i的离线朋友数,然后一条边一条边搜就行了. 代码: #include <stdio.h> #include <ctime>

HDU - 6185 Covering(暴搜+递推+矩阵快速幂)

Covering Bob's school has a big playground, boys and girls always play games here after school. To protect boys and girls from getting hurt when playing happily on the playground, rich boy Bob decided to cover the playground using his carpets. Meanwh

hdu 1238 Substrings (暴搜,枚举)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1238 Substrings Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8391    Accepted Submission(s): 3862 Problem Description You are given a number of

[HDU 5135] Little Zu Chongzhi&#39;s Triangles (dfs暴搜)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5135 题目大意:给你n条边,选出若干条边,组成若干个三角形,使得面积和最大.输出最大的面积和. 先将边从小到大排序,这样前面的两条边加起来如果不大于第三条边就可以跳出,这是一个存在性条件. dfs(int idx,int now,int cnt,int nowmax)代表我当前处理的是第idx条边,已经加入边集的有cnt条边,当前的边的长度和为now,组成的最大面积和为nowmax. 暴力枚举每个三

HDU 4284 Travel Folyd预处理+dfs暴搜

题意:给你一些N个点,M条边,走每条边要花费金钱,然后给出其中必须访问的点,在这些点可以打工,但是需要先拿到证书,只可以打一次,也可以选择不打工之直接经过它.一个人从1号点出发,给出初始金钱,问你能不能访问所以的点,并且获得所以证书. 题解:目标是那些一定要访问的点,怎么到达的我们不关心,但是我们关系花费最少的路径,而且到达那个点后是一定要打工的,如果只是经过,那么在求花费最少的路径的时候已经考虑过了. 因此先用Folyd求出各个点直接的最短路径,由于N很小,又只要求出一个解,所以直接dfs暴搜

hdu 4400 离散化+二分+BFS(暴搜剪枝还超时的时候可以借鉴一下)

Mines Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1110    Accepted Submission(s): 280 Problem Description Terrorists put some mines in a crowded square recently. The police evacuate all peo

hdu 4848 Wow! Such Conquering! (暴搜+强剪枝)

Wow! Such Conquering! Time Limit: 15000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 0    Accepted Submission(s): 0 Problem Description There are n Doge Planets in the Doge Space. The conqueror of Doge Space