#include
<
iostream
>
using
namespace
std;
int
n,v;
int
f[
10010
];
int
main()
{
int
t;
scanf(
"
%d
"
,
&
t);
while
(t
--
){
int
v1;
scanf(
"
%d%d%d
"
,
&
v1,
&
v,
&
n);
v
-=
v1;
memset(f,
0x7F
,
sizeof
(f));
f[
0
]
=
0
;
for
(
int
i
=
1
;i
<=
n;
++
i){
int
w,c;
scanf(
"
%d%d
"
,
&
c,
&
w);
for
(
int
j
=
w;j
<=
v;
++
j)
if
(f[j]
>
f[j
-
w]
+
c)
f[j]
=
f[j
-
w]
+
c;
}
if
(f[v]
>=
0xFFFFFFF
) printf(
"
This is impossible.\n
"
);
else
printf(
"
The minimum amount of money in the piggy-bank is %d.\n
"
,f[v]);
}
return
0
;
}
posted on 2009-04-25 19:40
xfstart07 阅读(125)
评论(0) 编辑 收藏 引用 所属分类:
代码库