https://vjudge.net/contest/67836#problem/I

Given a set of sticks of various lengths, is it possible to join them end-to-end to form a square?

Input

The first line of input contains N, the number of test cases. Each test case begins with an integer 4 <= M <= 20, the number of sticks. M integers follow; each gives the length of a stick - an integer between 1 and 10,000.

Output

For each case, output a line containing "yes" if is is possible to form a square; otherwise output "no".

Sample Input

3
4 1 1 1 1
5 10 20 30 40 50
8 1 7 2 6 4 4 3 5

Sample Output

yes
no
yes

代码:

#include <bits/stdc++.h>
using namespace std; int n, ave, maxx, sum;
int a[50];
bool flag = false;
int vis[50]; void dfs(int num, int len, int start) {
if(flag)
return; if(num == 4) {
flag = true;
return ;
} if(len == ave) {
dfs(num + 1, 0, 1);
if(flag)
return ;
} for(int i = start; i <= n; i ++) {
if(vis[i] == 0 && len + a[i] <= ave) {
vis[i] = 1;
dfs(num, len + a[i], i + 1);
vis[i] = 0;
if(flag)
return ;
}
}
} int main() {
int T;
scanf("%d", &T);
while(T --) {
scanf("%d", &n);
maxx = 0, sum = 0;
for(int i = 1; i <= n; i ++) {
scanf("%d", &a[i]);
sum += a[i];
}
sort(a + 1, a + 1 + n);
maxx = a[n];
ave = sum / 4;
if(sum % 4 != 0 || maxx > ave) {
printf("no\n");
continue;
}
memset(vis, 0, sizeof(vis));
flag = false;
dfs(0, 0, 1);
if(flag)
printf("yes\n");
else
printf("no\n");
}
return 0;
}

  写这个专题的时候想到暑假被搜索支配的恐惧 写不出来或者很紧张的时候就很喜欢听《最佳歌手》

ZOJ 1909 I-Square的更多相关文章

  1. zoj 2835 Magic Square(set)

    Magic Square Time Limit: 2 Seconds      Memory Limit: 65536 KB In recreational mathematics, a magic ...

  2. ZOJ题目分类

    ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...

  3. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  4. ZOJ 3122 Sudoku

    Sudoku Time Limit:10000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status ...

  5. POJ 2296 Map Labeler / ZOJ 2493 Map Labeler / HIT 2369 Map Labeler / UVAlive 2973 Map Labeler(2-sat 二分)

    POJ 2296 Map Labeler / ZOJ 2493 Map Labeler / HIT 2369 Map Labeler / UVAlive 2973 Map Labeler(2-sat ...

  6. ZOJ 3890 Wumpus

    Wumpus Time Limit: 2 Seconds      Memory Limit: 65536 KB One day Leon finds a very classic game call ...

  7. POJ 1502 MPI Maelstrom / UVA 432 MPI Maelstrom / SCU 1068 MPI Maelstrom / UVALive 5398 MPI Maelstrom /ZOJ 1291 MPI Maelstrom (最短路径)

    POJ 1502 MPI Maelstrom / UVA 432 MPI Maelstrom / SCU 1068 MPI Maelstrom / UVALive 5398 MPI Maelstrom ...

  8. POJ 3076 / ZOJ 3122 Sudoku(DLX)

    Description A Sudoku grid is a 16x16 grid of cells grouped in sixteen 4x4 squares, where some cells ...

  9. ZOJ - 3890 Wumpus(BFS基础题)

    Wumpus Time Limit: 2 Seconds      Memory Limit: 65536 KB One day Leon finds a very classic game call ...

随机推荐

  1. hadoop jobhistory访问界面长时间打不开

    1.浏览器无法直接通过url访问 可能原因 :主机名未配置,因此无法识别,在 c:\windows\system32\drivers\etc 目录添加主机名和对应ip hostname1[主机名 ] ...

  2. Spark_安装配置_运行模式

    一.Spark支持的安装模式: 1.伪分布式(一台机器即可) 2.全分布式(至少需要3台机器) 二.Spark的安装配置 1.准备工作 安装Linux和JDK1.8 配置Linux:关闭防火墙.主机名 ...

  3. 运用busybox构建最小根文件系统

    平台:vmware下ubuntu14.04前期准备:安装交叉编译环境arm-linux-gcc-4.5.1;下载完成BusyBox 1.23.2一.busybox构建1.make menuconfig ...

  4. Qt——父对象、布局

    设置父对象两个好处:(1)加入析构树(2)和父对象一起显示 设置布局后,子控件自动被设置父对象 设置父对象两个好处:(1)加入析构树(2)和父对象一起显示

  5. HttpClient的Content-Type设置

    HttpClient的Content-Type设置 最近在对接公司内容的一个云服务的时候,遇到一个问题,就是如果使用HttpClient如何设置post时候的Content-Type? public ...

  6. express with bower in websotrm

    0. To install bower , run the following command in webstorm terminal(alt+f12) npm install bower bowe ...

  7. MySQL高级第五章——主从复制

    一.复制的基本原理 slave会从master读取binlog(二进制日志文件)进行数据同步 步骤: 详细操作步骤请参见:http://www.cnblogs.com/luckcs/articles/ ...

  8. (转)Gmail,你必须了解的12个邮件编码问题

    转载地址:http://www.maildesign.cn/archives/1537 1.Gmail 不支持style=” display:none”2.Gmail不支持内嵌式CSS样式3.Gmai ...

  9. CakePHP模型中使用join的多种写法

    Cake写法 App::import("Model","Client"); $this->Client = & new Client(); $th ...

  10. DSP5509的定时器实验-第2篇

    1. 导入Easy5509开发板的例程EX02_TIME,5509有2个16位的定时器,有点少啊 2. 直接编译,提示找不到CSL.h,其实我也好奇,CSL库是从哪里来的?RTS库从哪里来的?头文件在 ...