Uva 10130-SuperSale(0-1背包)
来源:互联网 发布:周杨青的淘宝店铺 编辑:程序博客网 时间:2024/05/18 03:59
题目链接:点击打开链接
裸的0-1背包 。。只不过相当于有多个背包,因为这些背包互相独立,求和相加就ok
#include <algorithm>#include <iostream>#include <cstring>#include <cstdlib>#include <string>#include <cctype>#include <vector>#include <cstdio>#include <cmath>#include <queue>#include <stack>#include <map>#include <set>#define maxn 1005#define _ll __int64#define ll long long#define INF 0x3f3f3f3f#define Mod 1<<40+10#define pp pair<int,int>#define ull unsigned long longusing namespace std;int n,v[maxn],w[maxn],m,G;int cal(int V){int dp[35];memset(dp,0,sizeof(dp));for(int i=1;i<=n;i++)for(int j=V;j>=v[i];j--)dp[j]=max(dp[j],dp[j-v[i]]+w[i]);return dp[V];}int main(){int T;scanf("%d",&T);while(T--){scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d%d",&w[i],&v[i]);int s=0;scanf("%d",&m);for(int i=0;i<m;i++){scanf("%d",&G);s+=cal(G);}printf("%d\n",s);}return 0;}
1 0
- Uva 10130-SuperSale(0-1背包)
- UVa 10130 SuperSale (0-1背包)
- UVA 10130 SuperSale 0-1背包
- UVA 10130 - SuperSale(0-1背包问题)
- UVA 10130 SuperSale(背包)
- UVa 10130 - SuperSale 背包
- uva 10130 SuperSale(01背包)
- UVA - 10130 SuperSale (01背包)
- uva 10130 SuperSale (01背包)
- uva 10130 - SuperSale(01背包)
- Uva-10130 SuperSale 01背包
- UVa 10130 SuperSale(DP_01背包)
- SuperSale - UVa 10130 01背包
- 【UVA】10130-SuperSale(01背包)
- UVA 10130 SuperSale(01背包)
- uva 10130 - SuperSale(01背包简单变换)
- UVA - 10130 - SuperSale (动态规划 - 01背包)
- UVA 10130 SuperSale(dp + 01背包)
- Jdom解析XML
- GetWindowRect与GetClientRect 的区别
- Random Number系列:几何分布(geometric)随机变量的模拟
- php变量引用和计数_refcount_gc和is_ref_gc
- c#抽象函数
- Uva 10130-SuperSale(0-1背包)
- 关于angularjs 的ng-repeat 多行遍历(ng-repeat-start)
- easyui 使用loading"正在加载..." 风格的加载提示信息
- 总结IT的知识基础,开博客写个书,汇总一些华为常用的知识
- GetWindowRect与GetClientRect 的区别
- LINUX程序设计--学习笔记
- jsp与java bean
- 【Unity 笔记】文件的写入与读取(2)
- 在Datatable,DataView和DataGridView中不显示重复的记录