会员
周边
众包
新闻
博问
闪存
赞助商
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
代码改变世界
Cnblogs
Dashboard
Login
Home
Contact
Gallery
Subscribe
RSS
一切随心
编程菜园
分硬币
2006-10-31 15:59
老博客哈
阅读(
489
) 评论(
0
)
编辑
收藏
举报
/**/
/*
http://acm.hnu.cn
:8080/online/?action=problem&type=show&id=10415
*/
#include
<
iostream
>
#include
<
cstring
>
#include
<
vector
>
using
namespace
std;
int
main()
{
int
m;
//
硬币数目
int
v[
100
];
//
硬币面值
bool
isIn[
50001
];
//
硬币额度存在,则设置为true
vector
<
int
>
num;
//
所有能够获取的面额
int
i, j;
while
(cin
>>
m)
{
int
total
=
0
;
for
(i
=
0
; i
<
m; i
++
)
{
cin
>>
v[i];
total
+=
v[i];
}
memset(isIn,
false
,
sizeof
(isIn));
num.clear();
num.push_back(
0
);
for
(i
=
0
; i
<
m; i
++
)
{
int
length
=
num.size();
for
(j
=
0
; j
<
length; j
++
)
{
if
(
!
isIn[ v[i]
+
num[j] ])
{
isIn[ v[i]
+
num[j] ]
=
true
;
num.push_back(v[i]
+
num[j]);
}
}
}
for
(i
=
total
/
2
; i
>=
0
; i
--
)
{
if
(isIn[i])
{
cout
<<
total
-
i
-
i
<<
endl;
break
;
}
}
}
return
0
;
}
不要轻易认为就是Greedy了哈
会员力量,点亮园子希望
刷新页面
返回顶部
About