题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1518

题目大意:根据题目所给的几条边,来判断是否能构成正方形,一个很好的深搜应用,注意剪枝,以防超时!

  1. #include <iostream>
  2. #include <cstdio>
  3. #include<algorithm>
  4. #include <cstring>
  5. using namespace std;
  6. int ap[],visit[];
  7. int l,n;
  8. int dfs(int len,int gen,int iqq)
  9. {
  10. if (gen==)
  11. return ;
  12. for(int i=iqq; i<n; i++)
  13. {
  14. //cout<<visit[len]<<endl;
  15. if (!visit[i])
  16. {
  17. visit[i]=;
  18. if (len+ap[i]==l)
  19. {
  20. //cout<<len<<endl;
  21. if(dfs(,gen+,))
  22. return ;
  23. }
  24. else if (len+ap[i]<l)
  25. {
  26. //cout<<len<<endl;
  27. if(dfs(len+ap[i],gen,i)) return ;
  28. }
  29. visit[i]=;
  30. }
  31. }
  32. return ;
  33. }
  34. int main ()
  35. {
  36. int t,sum;
  37. while (cin>>t)
  38. {
  39. while (t--)
  40. {
  41. cin>>n;
  42. sum=;
  43. //Max=0;
  44. for (int i=; i<n; i++)
  45. {
  46. cin>>ap[i];
  47. sum+=ap[i];
  48. }
  49. memset(visit,,sizeof(visit));
  50. sort(ap,ap+n);
  51. if (sum%==&&n>=&&ap[n-]<=sum/)
  52. {
  53.  
  54. l=sum/;
  55. if (dfs(,,))
  56. printf ("yes\n");
  57. else
  58. printf ("no\n");
  59. //cout<<n<<endl;
  60. }
  61. else printf ("no\n");
  62. }
  63. }
  64. }

hdu 1518 Square(深搜+剪枝)的更多相关文章

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

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

  2. Hdu3812-Sea Sky(深搜+剪枝)

    Sea and Sky are the most favorite things of iSea, even when he was a small child.  Suzi once wrote: ...

  3. poj1190 生日蛋糕(深搜+剪枝)

    题目链接:poj1190 生日蛋糕 解题思路: 深搜,枚举:每一层可能的高度和半径 确定搜索范围:底层蛋糕的最大可能半径和最大可能高度 搜索顺序:从底层往上搭蛋糕,在同一层尝试时,半径和高度都是从大到 ...

  4. UVA 10160 Servicing Stations(深搜 + 剪枝)

    Problem D: Servicing stations A company offers personal computers for sale in N towns (3 <= N < ...

  5. ACM 海贼王之伟大航路(深搜剪枝)

    "我是要成为海贼王的男人!" 路飞他们伟大航路行程的起点是罗格镇,终点是拉夫德鲁(那里藏匿着"唯一的大秘宝"--ONE PIECE).而航程中间,则是各式各样的 ...

  6. POJ-1724 深搜剪枝

    这道题目如果数据很小的话.我们通过这个dfs就可以完成深搜: void dfs(int s) { if (s==N) { minLen=min(minLen,totalLen); return ; } ...

  7. Block Breaker HDU - 6699(深搜,水,写下涨涨记性)

    Problem Description Given a rectangle frame of size n×m. Initially, the frame is strewn with n×m squ ...

  8. 一本通例题-生日蛋糕——题解<超强深搜剪枝,从无限到有限>

    题目传送 显然是道深搜题.由于蛋糕上表面在最底层的半径确认后就确认了,所以搜索时的面积着重看侧面积. 找维度/搜索面临状态/对象:当前体积v,当前外表面面积s,各层的半径r[],各层的高度h[]. 可 ...

  9. HDOJ/HDU 1015 Safecracker(深搜)

    Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Kle ...

随机推荐

  1. ABP框架设置默认语言

    在Global.asax文件中设置 private readonly IAbpWebLocalizationConfiguration _webLocalizationConfiguration; p ...

  2. C++调用Asprise OCR识别图片

    在一个识别软件中发现了Asprise OCR的"身影",上官网查了一下相关信息,发现功能挺强大的,识别印刷体应该不错,遗憾的是好像不能识别中文,不过不知道它对扭曲后的英文识别能力怎 ...

  3. selenide UI自动化进阶二 pageObject实现页面管理

    首先定义登录页面,上代码吧 LoginPage.java package com.test.selenium.page; import org.openqa.selenium.By; import s ...

  4. Daily Scrum02 12.03

    Daily Scrum03 12.03 一天过去了,新的一天即将到来,我们组仍旧干劲十足呢~ Member Today's Task Tomorrow's Task 李孟 孟神有点累了呢 task85 ...

  5. PhpStorm 配置数据库

    点击软件右边的 Database

  6. Spring Boot学习(二):配置文件

    目录 前言 方式1:通过配置绑定对象的方式 方式2:@Value("${blog.author}")的形式获取属性值 相关说明 注解@Value的说明 参考 前言 Spring B ...

  7. java-2018-01-17计划

    1.一句英语 包括单词 2.一个java版本的设计模式 参考:https://github.com/iluwatar/java-design-patterns 学习了抽象工厂模式 总结:java的RS ...

  8. incorrect integer value for column 问题解决

    最近在用zend框架,然后装了一个项目,发现注册的时候出现 General error: 1366 Incorrect integer value: '' for column 'user_id' a ...

  9. CSS的基本使用

    CSS的出现就是为了将HTML的内容与样式分离 CSS的书写方式 selector{ key:value } h1{ color: blue; } <!DOCTYPE html> < ...

  10. doget,doPost在底层走的是service

    doget,doPost在底层走的是service 因为在源码上 先执行service方法 然后再调用doget,doPost方法