吴队长征婚

Time Limit: 20 Sec  Memory Limit: 256 MB

题目连接

http://acm.uestc.edu.cn/#/contest/show/61

Description

吴队长征婚这件事因为请客而没有传出去(虽然他忘了请一个队吃饭),于是吴队长高兴地玩起了木棒。吴队长拿了一些长度相同的木(guang)棒(gun),随机的把它们截成了N段,每一段最长50。现在他想把这些木棒还原成原来的状态,但是他忘记了原来的木棒有多少根,也忘记了每一根有多长。请帮助他设计一个程序,帮他计算之前木棒可能的最小长度。输入数据保证每一段木棒长度都大于0。

Input

输入有多组数据,每组数据分为两行。
第一行一个整数N,表示截断之后木棒的个数。1≤N≤64
第二行N个整数,表示截断之后的每一段小木棒的长度。 当N=0时,表示输入结束。

Output

每组数据输出一个整数占一行,表示原木棒可能的最小长度。

Sample Input

9
5 2 1 5 2 1 5 2 1
4
1 2 3 4
0

Sample Output

6
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题 吴队长征婚 爆搜的更多相关文章

  1. 2015 UESTC 搜索专题F题 Eight Puzzle 爆搜

    Eight Puzzle Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 ...

  2. 2015 UESTC 搜索专题C题 基爷与加法等式 爆搜DFS

    基爷与加法等式 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Desc ...

  3. 2015 UESTC 搜索专题K题 秋实大哥の恋爱物语 kmp

    秋实大哥の恋爱物语 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 De ...

  4. 2015 UESTC 搜索专题B题 邱老师降临小行星 记忆化搜索

    邱老师降临小行星 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Des ...

  5. 2015 UESTC 搜索专题N题 韩爷的梦 hash

    韩爷的梦 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Descrip ...

  6. 2015 UESTC 搜索专题M题 Palindromic String 马拉车算法

    Palindromic String Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/s ...

  7. 2015 UESTC 搜索专题J题 全都是秋实大哥 kmp

    全都是秋实大哥 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Desc ...

  8. 2015 UESTC 搜索专题D题 基爷的中位数 二分

    基爷的中位数 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Descr ...

  9. 2015 UESTC 搜索专题A题 王之迷宫 三维bfs

    A - 王之迷宫 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Des ...

随机推荐

  1. tar解压与压缩

    1.解压 tar -zxvf  压缩文件名  -C 指定的目录   (制定的目录必须存在) 2.压缩 tar -czvf  压缩后的文件名   要压缩的文件夹

  2. 使用showplan.sql分析sql Performance

    在HelloDBA网站找到一个分析sql性能的工具-showplan,记录一下 showplan.sql下载路径:http://www.HelloDBA.com/Download/showplan.z ...

  3. 多线程中的超时, 如Socket超时

    ; ,,, ->$port { print "-->$port\r"; #say "\r"; await Promise.anyof( Promis ...

  4. 【Python学习】使用BeautifulSoup解析HTML

    对于一个最简单的爬虫结构的代码是这样的. 也就是抓取出整个页面,然后创建一个BeautifulSoup对象. from urllib.request import urlopen from bs4 i ...

  5. ahttp

    # -*- coding: utf-8 -*- # @Time : 2018/8/20 14:35 # @Author : cxa # @File : chttp.py # @Software: Py ...

  6. 解决su – 后显示-bash-4.1#

    <1>现象 设置tfs的管理用户时. su - admin时,出现 -bash-4.1# <2>解决 chown  admin:admin /home/admin        ...

  7. 报错:Cobbler check 时报错

    报错:[root@test88 ~]# cobbler checkTraceback (most recent call last):  File "/usr/bin/cobbler&quo ...

  8. 用dom4j操作xml文件

    XML的全称是eXtensible Markup Language,即“可扩展标记语言”.XML文件的作用主要是数据存储,文件配置,数据传输. html与xml的区别是:①html语法松散,xml语法 ...

  9. LightOJ - 1010 Knights in Chessboard(规律)

    题目链接:https://vjudge.net/contest/28079#problem/B 题目大意:给你一个nxm的棋盘,问你最多可以放几个骑士让他们互相攻击不到.骑士攻击方式如下图: 解题思路 ...

  10. BestCoder #88(1001 1002)

    Find Q Accepts: 392 Submissions: 780 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/131 ...