HDU1518 Square
- #include<stdio.h>
- #include<string.h>
- #include<math.h>
- #include<stdlib.h>
- #define max(a, b)(a > b ? a : b)
- #define N 30
- int a[N], vis[N], n, k, f;
- void DFS(int s, int m, int d)//s为搜索起点 m为已组成的正方体的边数 d当前组成木棍的长度(正方体的一条边可由多个木棍组成)
- {
- int i;
- if(m == )
- {
- f = ;
- return ;
- }
- if(d == k)
- DFS(, m + , );
- for(i = s ; i < n ; i++)
- {
- if(!vis[i] && d + a[i] <= k)
- {
- vis[i] = ;
- DFS(i + , m, d + a[i]);
- vis[i] = ;
- if(f == )
- return ;
- }
- }
- }
- int main()
- {
- int t, sum, max, i;
- scanf("%d", &t);
- while(t--)
- {
- sum = f = max = ;
- scanf("%d", &n);
- for(i = ; i < n ; i++)
- {
- scanf("%d", &a[i]);
- sum += a[i];
- max = max(max, a[i]);
- }
- if(sum % != || max > sum / || n < )//正方体的边数为小数,长度最大的木棍大于正方体的边数。木棍总数小于4都不能组成正方体
- printf("no\n");
- else
- {
- k = sum / ;
- memset(vis, , sizeof(vis));
- DFS(, , );
- if(f == )
- printf("yes\n");
- else
- printf("no\n");
- }
- }
- return ;
- }
HDU1518 Square的更多相关文章
- HDU1518 Square(DFS,剪枝是关键呀)
Square Time Limit : 10000/5000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submi ...
- HDU1518 Square(DFS)
Square Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- HDU-1518 Square(DFS)
Square Time Limit : 10000/5000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submi ...
- HDU1518:Square(DFS)
Square Time Limit : 10000/5000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submi ...
- HDU1518 Square(DFS) 2016-07-24 15:08 49人阅读 评论(0) 收藏
Square Problem Description Given a set of sticks of various lengths, is it possible to join them end ...
- HDU1518 Square 【剪枝】
Square Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- [LeetCode] Matchsticks to Square 火柴棍组成正方形
Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match ...
- [LeetCode] Valid Word Square 验证单词平方
Given a sequence of words, check whether it forms a valid word square. A sequence of words forms a v ...
- [LeetCode] Valid Perfect Square 检验完全平方数
Given a positive integer num, write a function which returns True if num is a perfect square else Fa ...
随机推荐
- Android 面试题(经典)
1.Actvity的生命周期,生命周期中的onCreate与onResume有什么区别 Activity的生命周期有:onCreate,onStart,onRestart,onResume,onPau ...
- java 语言里 遍历 collection 的方式
我来简单说一下吧,一般有2种方法来遍历collection中的元素,以HashSet为例子HashSet hs=new HashSet();hs.add("hello");hs.a ...
- 用net匹配并替换iOS标准的emoji表情符号
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespaceCommo ...
- QSettings介绍
简介 QSettings类提供了持久的跨平台应用程序设置. 用户通常期望应用程序记住它的设置(窗口大小.位置等)所有会话.这些信息通常存储在Windows系统注册表,OS X和iOS的属性列表文件中. ...
- UVa 116 (多段图的最短路) Unidirectional TSP
题意: 有一个m行n列的正整数环形矩阵(即矩阵第一行的上一行是最后一行,最后一行的下一行是第一行),从第一列的任意位置出发,每次只能向右,右上,右下三个方向行走,输出路径及路径上所有数之和的最大值,多 ...
- BNU 4188 Superprime Rib【BFS】
题意:给出n,输出n位超级质数,超级质数的定义为“依次去掉右边一位后仍然为质数的数” 因为一个n位质数去掉右边一位数之后仍然为质数,说明它是由n-1位超级质数演变而来的, 同理,n-1位超级质数也由n ...
- Java知识点:琐碎知识点(2)
49个关键字一览 abstract default if private this boolean do implements protected throw break double import ...
- Java [Leetcode 191]Number of 1 Bits
题目描述: Write a function that takes an unsigned integer and returns the number of ’1' bits it has (als ...
- ASP.NET服务器控件对应的HTML标签
了解ASP.NET的控件最终解析成什么HTML代码,有助于我们对ASP.NET更深的了解,在使用JS交互时也知道如何操作. ASP.NET 服务器控件渲染到客户端之后对应的HTML标签讲解. labe ...
- loadrunner 发送gzip压缩json格式(转)
转:http://blog.csdn.net/gzh0222/article/details/7711281 使用java vuser实现,发送gzip压缩json格式. /* * LoadRunne ...