#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>using namespace std;#define maxm 50005#define maxn 15int n, m, y;int weight[maxn], value[maxn];int f[maxm];void input(){ scanf("%d%d", &m, &y); scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d", &weight[i], &value[i]); weight[i] /= 1000; }}int work(){ double x = m; for (int i = 0; i < y; i++) x *= 1.1; int temp = ceil(x) / 1000 + 2; memset(f, 0, sizeof(f)); for (int i = 0; i < n; i++) for (int j = weight[i]; j <= temp; j++) f[j] = max(f[j], f[j - weight[i]] + value[i]); int ret = m; for (int i = 0; i < y; i++) ret = ret + f[ret / 1000]; return ret;}int main(){ int t; scanf("%d", &t); while (t--) { input(); printf("%dn", work()); } return 0;}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)