您的位置:首页 > 其它

[HDOJ 4501] 小明系列故事——买年货

2015-07-26 17:24 399 查看

题目描述

小明系列故事——买年货

解题思路

多个01背包的组合.

参考代码

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 110;
struct Node{
int price,score,val;
}s[maxn];
int dp[maxn][maxn][7];
int main()
{
int n,v1,v2,k;
while (~scanf("%d %d %d %d",&n,&v1,&v2,&k)){
memset(dp,0,sizeof(dp));
for (int i = 1;i <= n;i++)  scanf("%d %d %d",&s[i].price,&s[i].score,&s[i].val);
for (int i = 1;i <= n;i++)
for (int j = v1;j >= 0;j--)
for (int l = v2;l >= 0;l--)
for (int v = k;v >= 0;v--){
int t = 0;
if (j >= s[i].price)    t = max(t,dp[j-s[i].price][l][v]+s[i].val);
if (l >= s[i].score)    t = max(t,dp[j][l-s[i].score][v]+s[i].val);
if (v >= 1) t = max(t,dp[j][l][v-1]+s[i].val);
dp[j][l][v] = max(t,dp[j][l][v]);
}
printf("%d\n",dp[v1][v2][k]);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: