今夜是DP之夜~
#include <iostream>
#include <bits/stdc++.h>
#define maxn 2010
#define INF 0x3f3f3f3f
#define ll long long
using namespace std;
ll d[50010];//v,m
int p[maxn],w[maxn];
int main() {
int T;
int V1,V2;
int M;
cin>>T;
while(T--){
cin>>V1>>V2;
cin>>M;
memset(d,INF, sizeof(d));
for(int i = 0;i<M;i++){
cin>>p[i]>>w[i];
}
d[V1] = 0;
for(int i = V1+1;i<=V2;i++){
for(int j = 0;j<M;j++){
if(i>=w[j]){
d[i] = min(d[i],d[i-w[j]] + p[j]);
}
}
}
if(d[V2]<INF)
{
cout<<"The minimum amount of money in the piggy-bank is "<<d[V2]<<"."<<endl;
}
else{
cout<<"This is impossible."<<endl;
}
}
return 0;
}
/**
3
10 110
2
1 1
30 50
10 110
2
1 1
50 30
1 6
2
10 3
20 4
**/