关闭

poj 2063 Investment

273人阅读 评论(0) 收藏 举报
分类:

完全背包的变形操作


#include<iostream>
#include<string.h>
#include<math.h>
#include<fstream>
#include<algorithm>
#include<stdio.h>
#include<queue>
#include<vector> 
#define MAXSIZE 100
using namespace std;
int N = 0, original = 0, years = 0;
int value[11], interest[11], d = 0; 
int dp[200010];
int ans = 0;
int main()
{
    //freopen("data_2063.txt","r",stdin);
    scanf("%d", &N);
    while(N--)
    {
        ans = 0;
        memset(dp, 0, sizeof(dp));
        scanf("%d%d", &original, &years);
        scanf("%d", &d);
        for (int i = 0; i < d; i++)
        {
            scanf("%d%d", &value[i], &interest[i]);
            value[i] /= 1000;
        }
        ans = original;
        for (int i = 0; i < years; i++)
        {
            memset(dp, 0, sizeof(dp));   
            original = ans / 1000;
            for (int j = 0; j < d; j++)
            {
                for (int k = 0; k <= original; k++)
                {
                    if (k >= value[j])
                    {
                        dp[k] = max (dp[k], dp[k - value[j]] + interest[j]);
                    }
                }
            }
            ans += dp[original];
        }
        printf("%d\n", ans);
    }
    return 0;
}




0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场