SuperSale UVA
来源:互联网 发布:mac卸载软件 编辑:程序博客网 时间:2024/06/06 15:37
01背包
题目描述:一家人去超市买东西,各种物品有价格和重量,每个人都有自己的背包容量,求这一家人能够获得最大价值。
解题分析:刚开始被这题给唬住了,想成了如果一个物品被某人买了,则其他人不可以卖这个物品,那这就难了。但是想想也该明白那家超市一种物品只卖一件啊,超时的物品是任意多的。这题就是单纯的01背包。
代码如下:
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;const int INF = 0x3f3f3f3f;const int maxn = 1000 + 10;int v[maxn];int w[maxn];int dp[maxn];int peo[maxn];int N,M;int main(){ int kase; cin >> kase; while(kase--) { memset(dp,0,sizeof(dp)); cin >> N; for(int i = 1; i <= N; i++) { scanf("%d %d",&v[i],&w[i]); } cin >> M; for(int i = 0; i < M; i++) { scanf("%d",&peo[i]); } for(int i = 1; i <= N; i++) { for(int j = 30; j >= w[i]; j--) { dp[j] = max(dp[j],dp[j-w[i]] + v[i]); } } int ans = 0; for(int i = 0; i < M; i++) ans += dp[peo[i]]; cout << ans << endl; } return 0;}
阅读全文
0 0
- SuperSale UVA
- uva 10130 SuperSale
- UVA 10130 SuperSale
- Uva 10130 - SuperSale
- UVa 10130 - SuperSale
- UVa 10130 - SuperSale
- UVa 10130 - SuperSale 背包
- uva 10130 - SuperSale
- UVa 10130 - SuperSale
- UVa 10130 - SuperSale
- Uva-10130-SuperSale
- UVa:10130 SuperSale
- UVA - 10130 SuperSale
- UVa 10130 - SuperSale
- UVa 10130 - SuperSale
- uva 10130 SuperSale
- uva 10130 SuperSale
- UVa 10130—SuperSale
- [LeetCode] Search in Rotated Sorted Array II
- .mat文件后缀名消失
- CSS布局奇淫巧计之-强大的负边距
- 使用枚举实现单例模式
- HDU
- SuperSale UVA
- [USACO16OPEN]Closing the Farm_Silver(联通分量+逆向边处理+并查集)
- Android PatternMatcher
- iOS开发中静态库的制作
- RPC原理
- 基于 Laravel 的 Vue.js 学习
- oracle存储过程中的异常处理
- UVA.12716 GCD XOR (暴力枚举 数论GCD)
- SQL 撤销索引、表以及数据库