HDU 1455 http://acm.hdu.edu.cn/showproblem.php?pid=1455
#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的更多相关文章
- HDU 4911 http://acm.hdu.edu.cn/showproblem.php?pid=4911(线段树求逆序对)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4911 解题报告: 给出一个长度为n的序列,然后给出一个k,要你求最多做k次相邻的数字交换后,逆序数最少 ...
- 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 ...
- HDU-4632 http://acm.hdu.edu.cn/showproblem.php?pid=4632
http://acm.hdu.edu.cn/showproblem.php?pid=4632 题意: 一个字符串,有多少个subsequence是回文串. 别人的题解: 用dp[i][j]表示这一段里 ...
- 待补 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/ ...
- HDU-1257 导弹拦截系统 http://acm.hdu.edu.cn/showproblem.php?pid=1257
Problem Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高 ...
- 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 ...
- KMP应用http://acm.hdu.edu.cn/showproblem.php?pid=2594
riemann与marjorie拼接后riemannmarjorie前缀与后缀公共部分为 rie 长度为 3(即next[l] = next[14]的值,l为拼接后的长度)但:aaaa与aa拼接后aa ...
- HDU 2544 最短路 http://acm.hdu.edu.cn/showproblem.php?pid=2544
//代码: //方法1:Dijkstra's Algorithm #include<stdio.h> #include<math.h> #include<string.h ...
- HDU1973 http://acm.hdu.edu.cn/showproblem.php?pid=1973
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<queue> #inc ...
随机推荐
- Xmanager Enterprise Linking VM Redhat Linux AS4.7 X64–Server Configuration
[root@localhost ~]# vi /etc/inittab ## inittab This file describes how the INIT process shou ...
- Android开发之消息机制
转:http://stackvoid.com/introduction-to-Message-Handler-in-Android/ http://blog.dreamtobe.cn/2016/03/ ...
- Unity 教程和源码
12个Unity3D游戏源码 - 新手必备 愤怒的小鸟攻略技巧秘籍 NGUI 教程收录大全:http://forum.exceedu.com/forum/forum.php?mod=viewthre ...
- hdu 4972 A simple dynamic programming problem (转化 乱搞 思维题) 2014多校10
题目链接 题意:给定一个数组记录两队之间分差,只记分差,不记谁高谁低,问最终有多少种比分的可能性 分析: 类似cf的题目,比赛的时候都没想出来,简直笨到极点..... 最后的差确定,只需要计算和的种类 ...
- struts2中改变struts.xml默认路径
struts2.X配置文件默认存放路径在/WEB-INF/classes目录下,即将struts.xml放在src的目录下. 但是为了方便管理,开发人员把struts.xml放到其他位置,处理方法如下 ...
- ASP.NET MVC 学习3、Controller左手从Model获取数据,右手传递到View页面
参考:http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/accessing-your-models-dat ...
- 终极解决方案:windows10开机黑屏,死机
windows10开机黑屏,死机一般情况都是由于双显卡中的独立显卡驱动造成的! 那么试着升级一下你的BIOS吧!一定要在官网下载你对应的BIOS驱动,然后双击安装,这个时候就别再动机子了,让他自己刷新 ...
- 原创-兼容IE8的placeholder
!function (o) { o.fn.extend({ PlaceHolder: function () { var _isEmpty = function (val) { return (val ...
- 为什么要CGI
1.微软为什么使用CGI? 微软曾经在不同场合极力推荐它的ASP技术,以取代CGI标准,这对微软当然是有利的,但是对一个网站来说ASP是不是一个明智的选择呢?这是一个值得大家深思熟虑的问题. 因为一旦 ...
- exec、eval
#!/usr/bin/env python3 # -*- coding: utf-8 -*- #info #warning def log(message): print('------------- ...