2015 UESTC 搜索专题E题 吴队长征婚 爆搜
吴队长征婚
Time Limit: 20 Sec Memory Limit: 256 MB
题目连接
http://acm.uestc.edu.cn/#/contest/show/61
Description
Input
第一行一个整数N,表示截断之后木棒的个数。1≤N≤64
第二行N个整数,表示截断之后的每一段小木棒的长度。 当N=0时,表示输入结束。
Output
每组数据输出一个整数占一行,表示原木棒可能的最小长度。
Sample Input
5 2 1 5 2 1 5 2 1
4
1 2 3 4
0
Sample Output
5
HINT
题意
题解:
爆搜题
剪枝1:大木棍长度只可能是sum的约数
剪枝2:重复的木棍就可以不用枚举了
剪枝3:每次都从最长的开始枚举
然后就可以AC了……
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** int a[],n,sum,num;
int vis[];
bool cmp(int aa,int bb)
{
return aa>bb;
} int dfs(int x,int y,int z,int len)
{
if(x==num)
return ;
for(int i=z+;i<n;i++)
{
if(vis[i])
continue;
if(y+a[i]==len)
{
vis[i]=;
if(dfs(x+,,-,len))
return ;
vis[i]=;
return ;
}
else if(y+a[i]<len)
{
vis[i]=;
if(dfs(x,y+a[i],i,len))
return ;
vis[i]=;
if(y==)
return ;
while(a[i]==a[i+])
i++;
}
}
return ;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
if(n==)
break;
sum=;
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
sort(a,a+n,cmp);
int i;
for(i=a[];i<=sum;i++)
{
if(sum%i==)
{
num=sum/i;
memset(vis,,sizeof(vis));
if(dfs(,,-,i))
break;
}
}
printf("%d\n",i);
}
}
2015 UESTC 搜索专题E题 吴队长征婚 爆搜的更多相关文章
- 2015 UESTC 搜索专题F题 Eight Puzzle 爆搜
Eight Puzzle Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 ...
- 2015 UESTC 搜索专题C题 基爷与加法等式 爆搜DFS
基爷与加法等式 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Desc ...
- 2015 UESTC 搜索专题K题 秋实大哥の恋爱物语 kmp
秋实大哥の恋爱物语 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 De ...
- 2015 UESTC 搜索专题B题 邱老师降临小行星 记忆化搜索
邱老师降临小行星 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Des ...
- 2015 UESTC 搜索专题N题 韩爷的梦 hash
韩爷的梦 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Descrip ...
- 2015 UESTC 搜索专题M题 Palindromic String 马拉车算法
Palindromic String Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/s ...
- 2015 UESTC 搜索专题J题 全都是秋实大哥 kmp
全都是秋实大哥 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Desc ...
- 2015 UESTC 搜索专题D题 基爷的中位数 二分
基爷的中位数 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Descr ...
- 2015 UESTC 搜索专题A题 王之迷宫 三维bfs
A - 王之迷宫 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Des ...
随机推荐
- 远程工具(SSH Secure)连接Centos出现中文乱码问题的解决办法
问题原因 使用远程工具进行连接时,如果linux有中文文件或目录,显示时会出现乱码,原因是linux编码是UTF-8,而远程工具默认是当前系统本地编码即GBK.所以解决方案是统一两者编码就OK了,但是 ...
- python进阶之内置函数和语法糖触发魔法方法
前言 前面已经总结了关键字.运算符与魔法方法的对应关系,下面总结python内置函数对应的魔法方法. 魔法方法 数学计算 abs(args):返回绝对值,调用__abs__; round(args): ...
- 浅析busybox如何集成到openwrt
背景 近日添加了一个包到openwrt中,在此过程中又对openwrt多了一些认识 这个包本身自带了kconfig,可直接在这个包里面执行make menuconfig进行配置,然后执行make 但要 ...
- caffe Python API 之Inference
#以SSD的检测测试为例 def detetion(image_dir,weight,deploy,resolution=300): caffe.set_mode_gpu() net = caffe. ...
- jplayer.js 与 video.js
HTML5 - 两款基于JS的视频播放器 都是基于h5 video 标签,如果不支持则会自动转成flash,这里个人比较推荐使用jplayer; 1.video.js pc端有时候会与视频打交道,如果 ...
- php 全文搜索解决方法
全套解决方案 xunsearch 一.安装编译工具 yum install make gcc g++ gcc-c++ libtool autoconf automake imake mysql-dev ...
- sort排序命令常见用法
sort -n 按数字排序 [root@test88 ~]# cat test.txt 19036 6111 24039 3660 20610 10937 32408 20744 8248 28255 ...
- MySQL之正则表达式
一.介绍 正则表达式用来描述或者匹配符合规则的字符串.它的用法和like比较相似,但是它又比like更强大,能够实现一些很特殊的规则匹配:正则表达式需要使用REGEXP命令,匹配上返回"1& ...
- jmeter-----查看结果树
在编写接口测试脚本的时候,需要进行调试和查看结果是否正常的情况,这个时候可以使用查看结果树组件进行. 查看结果树中展示了每一个取样器的结果.请求信息和响应信息,可以查看这些内容去分析脚本是否存在问题. ...
- 百度地图sdk定位和遇到的坑
封装定位服务类: import android.content.Context; import com.baidu.location.BDAbstractLocationListener; impor ...