poj 2063 Investment

poj 2063 Investment,第1张

poj 2063 Investment
#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;}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4928012.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存