#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define N 70 int f, vis[N], v, n, a[N]; int cmp(const void *a, const void *b)
{
return *(int *)b - *(int *)a;
} void DFS(int w, int sum)
{
int i;
if(sum == )
f = ;
else
{
for(i = ; i < n && f == ; i++)
{
if(!vis[i] && w - a[i] >= )
{
vis[i] = ;
if(w - a[i] == )
DFS(v, sum - a[i]);
else
DFS(w - a[i], sum - a[i]);
vis[i] = ;
if(w == a[i])
return ;
if(w == v && a[i] < v)
return ;
while(a[i] == a[i + ])
i++;
}
}
}
}
int main()
{
int i, sum;
while(scanf("%d", &n), n)
{
sum = f = ;
for(i = ; i < n ; i++)
{
scanf("%d", &a[i]);
sum += a[i];
}
qsort(a, n, sizeof(a[]), cmp);
for(v = a[] ; v <= sum ; v++)
{
if(sum % v == )
{
if(sum == v)
printf("%d\n", sum);
else
{
memset(vis, , sizeof(vis));
DFS(v, sum);
if(f == )
{
printf("%d\n", v);
break;
}
}
}
}
}
return ;
}

HDU 1455 http://acm.hdu.edu.cn/showproblem.php?pid=1455的更多相关文章

  1. HDU 4911 http://acm.hdu.edu.cn/showproblem.php?pid=4911(线段树求逆序对)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4911 解题报告: 给出一个长度为n的序列,然后给出一个k,要你求最多做k次相邻的数字交换后,逆序数最少 ...

  2. KMP(http://acm.hdu.edu.cn/showproblem.php?pid=1711)

    http://acm.hdu.edu.cn/showproblem.php?pid=1711 #include<stdio.h> #include<math.h> #inclu ...

  3. HDU-4632 http://acm.hdu.edu.cn/showproblem.php?pid=4632

    http://acm.hdu.edu.cn/showproblem.php?pid=4632 题意: 一个字符串,有多少个subsequence是回文串. 别人的题解: 用dp[i][j]表示这一段里 ...

  4. 待补 http://acm.hdu.edu.cn/showproblem.php?pid=6602

    http://acm.hdu.edu.cn/showproblem.php?pid=6602 终于能够看懂的题解: https://blog.csdn.net/qq_40871466/article/ ...

  5. HDU-1257 导弹拦截系统 http://acm.hdu.edu.cn/showproblem.php?pid=1257

    Problem Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高 ...

  6. http://acm.hdu.edu.cn/showproblem.php?pid=2579

    #include<stdio.h> #include<string.h> #include<queue> #define N 110 int m, n, k, x1 ...

  7. KMP应用http://acm.hdu.edu.cn/showproblem.php?pid=2594

    riemann与marjorie拼接后riemannmarjorie前缀与后缀公共部分为 rie 长度为 3(即next[l] = next[14]的值,l为拼接后的长度)但:aaaa与aa拼接后aa ...

  8. HDU 2544 最短路 http://acm.hdu.edu.cn/showproblem.php?pid=2544

    //代码: //方法1:Dijkstra's Algorithm #include<stdio.h> #include<math.h> #include<string.h ...

  9. HDU1973 http://acm.hdu.edu.cn/showproblem.php?pid=1973

    #include<stdio.h> #include<stdlib.h> #include<string.h> #include<queue> #inc ...

随机推荐

  1. Windows下tuxedo配置

    setenv.cmd rem (c) 2003 BEA Systems, Inc. All Rights Reserved. rem Copyright (c) 2000 BEA Systems, I ...

  2. 服务--web服务

    .面向对象和面向组件 .什么是Web服务 Web Service "Stack" .Web服务的应用分类 Web服务都是对象/组件技术在Internet中的延伸 面向对象和面向组件 ...

  3. bzoj2823

    最小圆覆盖 有个东西叫作随机增量法,具体可以baidu 这里来说说怎么求三点共圆 这其实就是求两条线段的交点 在编程中,我们解方程是比较麻烦的一个比较好的方法是利用相似三角形 设线段AB,CD交P,则 ...

  4. mssql修改链接数为默认值

    EXEC sys.sp_configure N'show advanced options', N'1'  RECONFIGURE WITH OVERRIDE GO EXEC sys.sp_confi ...

  5. 笨笨-歌词伴侣V1.2(酷狗KRC转LRC,LRC歌词批量下载)

      最近由于某些热心博友在我CSDN博客上使用了我的软件,提出了一些建议,看到自己的成果有人使用并且提出了一些建议,焉有不高兴之理!刚好碰上最近研究UI界面,有了一个初步的框架,就顺手将歌词相关功能集 ...

  6. FFmpeg 维基百科

    FFmpeg是一个自由软件,可以运行音频和视频多种格式的录影.转换.流功能[1],包含了libavcodec ─这是一个用于多个项目中音频和视频的解码器库,以及libavformat——一个音频与视频 ...

  7. Android-AnimationDrawable(二)

    首先可以先定义一个逐帧播放的xml: <?xml version="1.0" encoding="utf-8"?> <animation-li ...

  8. Android-判断当前网络是否可用

    1.声明权限 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 2. ...

  9. 【转】一致性hash算法(consistent hashing)

    consistent hashing 算法早在 1997 年就在论文 Consistent hashing and random trees 中被提出,目前在 cache 系统中应用越来越广泛: 1  ...

  10. Generate Parentheses java实现

    Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...