[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; }
相关文章推荐
- ZOJ - 2548 Prerequisites?
- 暑假第1周周报
- collection 集合实例
- iOS中获取UIWebView的各种信息
- hdu杭电 1113 Word Amalgamation
- 关于启动 Eclipse 弹出“Failed to load the JNI shared library jvm.dll”错误的解决方法!
- 阿里云服务器 ECS Ubuntu系统下PHP,MYSQL,APACHE2的安装配置
- HBase应用场景
- 【linux高级程序设计】(第八章)进程管理与程序开发 1
- BCB中进度条TProgressBar的使用
- nginx+tomcat集群配置
- 索尼克通信支付宝、超声波、蟋蟀和其他定制版本源代码
- [FOJ 1896] 神奇的魔法数
- NSOperation - 01
- HTML position元素
- ArcSDE当关系查询ArcMap与REST查询结果不一致问题的解决
- [未完]散列_分离链接法
- Java的string类为什么是不可变的
- FOJ 1893 内存管理 //模拟
- 垃圾邮件和贝叶斯过滤算法