POJ 2362 dfs 剪枝
来源:互联网 发布:mac命令行终端工具 编辑:程序博客网 时间:2024/04/29 09:06
题目大意:给你若干木棍的长度, 是否能组成正方形。
n必须大于等于4, sum必须能被4整除。
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <iomanip>
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 30;
const int inf = 0x3f3f3f3f;
int side, n;
int num[N];
bool vis[N];
bool dfs(int m, int len, int cur)
{
if(m==3)//回溯的条件
return true;
for(int i = cur; i<n; i++)
{
if(vis[i])
continue;
vis[i] = true;
if(len+num[i]<side)
{
if(dfs(m, len+num[i], i))
return true;
}
if(len + num[i] == side)
{
if(dfs(m+1, 0, 0))
return true;
}
vis[i] = false;
}
return false;
}
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
int sum = 0;
for(int i = 0; i<n;i++)
{
scanf("%d", &num[i]);
sum+=num[i];
}
if(sum%4==0&&n>=4)
side = sum/4;
else
{
printf("no\n");
continue;
}
memset(vis,false, sizeof(vis));
if(dfs(0,0,0))
printf("yes\n");
else
printf("no\n");
}
return 0;
}
- POJ 2362 DFS+剪枝
- POJ 2362 dfs 剪枝
- poj 2362 || zoj 1909 Square (DFS+剪枝)
- POJ 2362 HDOJ 1518 Square DFS剪枝
- POJ 2362 Square (DFS +剪枝)
- poj 2362 Square(dfs, 剪枝)
- poj 2192 DFS+剪枝
- poj 2248 DFS+剪枝
- poj 1190(DFS+剪枝)
- POJ 3009 DFS +剪枝
- POJ 2531 (DFS+剪枝)
- POJ 1011 (DFS+剪枝)
- poj 1847 DFS+剪枝
- poj 1011 dfs剪枝
- poj 1190(dfs剪枝)
- poj 3009 dfs+剪枝
- POJ 3009 DFS+剪枝
- poj 1190 dfs+剪枝
- 图像拼接
- Liunx中文字体与输入法的安装
- Servlet-验证码功能
- 下拉刷新控件
- php 生成随机字符串
- POJ 2362 dfs 剪枝
- 数据结构单链表
- php分页代码及总结
- 安装正版WinXP出现“缺少asms文件”问题的一个原因及解决方案
- js Array
- C# 4.0 大数的运算,BigInteger
- CSS3选择器
- c++的静态成员详解
- 数据对齐详解