#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. [Lintcode 3sum]三数之和(python,二分)

    题目链接:http://www.lintcode.com/zh-cn/problem/3sum/?rand=true# 用这个OJ练练python…这个题意和解法就不多说了,O(n^2lgn)就行了, ...

  2. Toad创建DBLINKsop

    Toad创建DBLINKsop 1.创建服务: 点击“测试”,出现如下测试窗口后点击更改登录,用户名和密码数据目标主机用户名.密码; 出现如下窗口后,点击“关闭”,然后点击“完成”即可; 2.创建db ...

  3. 关于<img>标签与文字垂直居中

    要让左边的图片与后面的文字居中,如下效果 HTML代码: <img class="iconCls" alt="最新客户端" src="${bas ...

  4. asp.net 使用JQuery 调用Ashx 后面直接写方法名,通过反射找到对应的方法

    using System.Reflection; public class Industry_Manager : IHttpHandler { HttpRequest gRequest = null; ...

  5. Make AngularJS $http service behave like jQuery.ajax()(转)

    There is much confusion among newcomers to AngularJS as to why the $http service shorthand functions ...

  6. django - settings

    1.doc - https://docs.djangoproject.com/en/1.6/topics/settings/ from django.conf import settings # 加载 ...

  7. Nginx - 指定log_format,常用于 Awstats 分析

    1. vim /etc/nginx/nginx.conf (下面格式, Awstats 使用) log_format new_log '$remote_addr - $remote_user [$ti ...

  8. 【C#学习笔记】退出程序

    1.this.Close();   只是关闭当前窗口,若不是主窗体的话,是无法退出程序的,另外若有托管线程(非主线程),也无法干净地退出: 2.Application.Exit();  强制所有消息中 ...

  9. 一些网站的Android客户端

    实际上就是浏览器(WebView),外面包装上了用户体验更好的外壳

  10. 仿酷狗音乐播放器开发日志二十七 用ole为窗体增加文件拖动功能(附源码)

    转载请说明原出处,谢谢~~ 中秋到了,出去玩了几天.今天把仿酷狗程序做了收尾,已经开发完成了,下一篇博客把完结的情况说一下.在这篇博客里说一下使用OLE为窗体增加文件拖拽的功能.使用播放器,我更喜欢直 ...