题解
#include
<
fstream
>
using
namespace
std;
int
n,ans;
int
a[
101
];
int
f[
101
][
10001
];
bool
check(
int
x){
for
(
int
i
=
1
;i
<=
n;
++
i)
if
(
!
f[i][x])
return
0
;
return
1
;
}
int
main()
{
ifstream cin(
"
Castle.in
"
);
ofstream cout(
"
Castle.out
"
);
cin
>>
n;
memset(f,
0
,
sizeof
(f));
ans
=
0xFFFFFFF
;
for
(
int
i
=
1
;i
<=
n;
++
i){
int
s
=
0
,l
=
0
,k;
cin
>>
k;
while
(k
!=-
1
){
a[
++
l]
=
k;
s
+=
k;
cin
>>
k;
}
f[i][
0
]
=
1
;
for
(k
=
1
;k
<=
l;
++
k)
for
(
int
j
=
s;j
>=
a[k];
--
j)
f[i][j]
=
f[i][j]
|
f[i][j
-
a[k]];
if
(s
<
ans) ans
=
s;
}
while
(ans){
if
(check(ans))
break
;
else
ans
--
;
}
cout
<<
ans
<<
endl;
return
0
;
}
posted on 2009-04-15 19:41
xfstart07 阅读(360)
评论(0) 编辑 收藏 引用 所属分类:
代码库