解题思路:sum%4!=0    , max<sum/4

#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>usingnamespace std;int a[100];bool vis[100],flag;int m,ave;bool dfs(int ans,int sum,int cnt){
    if(sum==ave)returntrue;
    for(int i=cnt;i<m;i++){
      if(a[i]==a[i-1]&&!vis[i-1])continue;
      if(!vis[i]&&a[i]<=ans){//shit !!!  <  
        vis[i]=true;
        if(a[i]==ans){
          if(dfs(ave,sum-a[i],0))
          returntrue;
        }
        elseif(dfs(ans-a[i],sum-a[i],i))
          returntrue;
        vis[i]=false;
        if(ans==ave)returnfalse;
        }
      }
      returnfalse;}int main(){
    int n,sum;
    scanf("%d",&n);
    while(n--){
      scanf("%d",&m);
      sum=0;
      for(int i=0;i<m;i++){
        scanf("%d",&a[i]);
        sum+=a[i];
      }
      sort(a,a+m);
      flag=false;
      ave=sum/4;
      if(a[m-1]>ave||sum%4!=0){
        cout<<"no"<<endl;
        continue;
      }
      else{
        memset(vis,false,sizeof(vis));
        if(dfs(ave,sum,0))
        flag=true;
      }
      if(flag) cout<<"yes"<<endl;
      else cout<<"no"<<endl;
    }
    return0;}

HDU 1518 Square的更多相关文章

  1. hdu 1518 Square(深搜+剪枝)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1518 题目大意:根据题目所给的几条边,来判断是否能构成正方形,一个很好的深搜应用,注意剪枝,以防超时! ...

  2. HDU 1518 Square 搜索

    Problem Description Given a set of sticks of various lengths, is it possible to join them end-to-end ...

  3. HDU 1518 Square(DFS)

    Problem Description Given a set of sticks of various lengths, is it possible to join them end-to-end ...

  4. hdu 1518 Square 深搜,,,,花样剪枝啊!!!

    Square Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  5. hdu 1518 Square 木棍建正方形【DFS】

    题目链接 题目大意: 题意就是输入棍子的数量和每根棍子的长度,看能不能拼成正方形. #include <bits/stdc++.h> using namespace std; int n, ...

  6. Square HDU 1518 搜索

    Square HDU 1518 搜索 题意 原题链接 给你一定若干个木棒,让你使用它们组成一个四边形,要求这些木棒必须全部使用. 解题思路 木棒有多种组合方式,使用搜索来进行寻找,这里需要进行优化,不 ...

  7. 杭电1518 Square(构成正方形) 搜索

    HDOJ1518 Square Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. hdu 1518 拼正方形

    本题来自:http://acm.hdu.edu.cn/showproblem.php?pid=1518 题意:输入几个长度,判断能否拼成正方形. 以下部分参考了网友代码,终于ac啦. #include ...

  9. hdu 5079 Square

    http://acm.hdu.edu.cn/showproblem.php?pid=5079 题意: n*n网格,每个格子可以涂黑色或白色,有的格子必须涂黑色 问最大白色正方形边长分别为0,1,2,… ...

随机推荐

  1. Automotive Security的一些资料和心得(7):AUTOSAR和Security

    1. 密码模块[1] 密码模块在Services Layer Configurable and common access to 密码子程序 硬件支持密码模块 2. 应用 应用和密码子程序分离 Cry ...

  2. BZOJ 3969 Low Power 解题报告

    我们首先将所有电池排序,那么我们可以找到一组最优方案,使得一台机器的能量之差是相邻两电池的能量之差. 然后我们就二分这个答案,从前往后贪心地选这个数对,然后看是否所有的数对都是满足条件的. 假设这个数 ...

  3. 开发安全的Web程序

    目录0x1:什么是安全的Web应用程序0x2:过滤输入的数据0x3:转义输出的数据0x4:Register Globals0x5:magic_quotes_gpc0x6:错误信息的报告0x7:文件的安 ...

  4. unity 与 android 协调工作 注意事项

    原地址:http://blog.csdn.net/u012085988/article/details/17436191 1.unity调android函数 AndroidJavaClass jc = ...

  5. Mysql的列索引和多列索引(联合索引)

    转自:http://blog.chinaunix.net/uid-29305839-id-4257512.html 创建一个多列索引:CREATE TABLE test (      id       ...

  6. JNI|在子线程中获得JNIEnv|AttachCurrentThread

    A JNI interface pointer (JNIEnv*) is passed as an argument for each native function mapped to a Java ...

  7. Visual Assist X

    老师推荐的一款vc++6.0插件 visual assistx_百度百科 http://baike.baidu.com/view/4439152.htm?fr=aladdin 下载 VC++6.0助手 ...

  8. JAVA实现word doc docx pdf excel的在线浏览 - 仿百度文库 源码

    我们具体实现思路是这样的 首先下载并安装openoffice和swftools openoffice下载地址:http://www.openoffice.org/download/index.html ...

  9. 【HDOJ】4267 A Simple Problem with Integers

    树状数组.Easy. /* 4267 */ #include <iostream> #include <string> #include <map> #includ ...

  10. git获取远端版本库上的Tag (没有clone[远端的版本库太大了])

    方法一 http://stackoverflow.com/questions/25815202/git-fetch-a-single-commit The git fetch command deli ...