Bone Collector HDU
来源:互联网 发布:linux alias 配置文件 编辑:程序博客网 时间:2024/06/06 23:15
Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also he went to the grave …
The bone collector had a big bag with a volume of V ,and along his trip of collecting there are a lot of bones , obviously , different bone has different value and different volume, now given the each bone’s value along his trip , can you calculate out the maximum of the total value the bone collector can get ?
The bone collector had a big bag with a volume of V ,and along his trip of collecting there are a lot of bones , obviously , different bone has different value and different volume, now given the each bone’s value along his trip , can you calculate out the maximum of the total value the bone collector can get ?
Followed by T cases , each case three lines , the first line contain two integer N , V, (N <= 1000 , V <= 1000 )representing the number of bones and the volume of his bag. And the second line contain N integers representing the value of each bone. The third line contain N integers representing the volume of each bone.
15 101 2 3 4 55 4 3 2 1
14
/*题解:01背包:状态转移方程为:f[i][j] = max(f[i - 1][j], f[i - 1][j - c[i]] + w[i]);*/#include<stdio.h>#include<queue>#include<iostream>#include<string.h>using namespace std;int f[1005][1005];int main(){int w[1005], c[1005];int n, v;int T;cin >> T;while (T--){cin >> n >> v;memset(f, 0, sizeof(f));memset(w, 0, sizeof(w));memset(c, 0, sizeof(c));for (int i = 1; i <= n; i++){cin >> w[i];//价值}for (int i = 1; i <= n; i++)cin >> c[i];//体积for (int i = 1; i <= n; i++){for (int j = 0; j <= v; j++){if (j >= c[i]){f[i][j] = max(f[i - 1][j], f[i - 1][j - c[i]] + w[i]);}elsef[i][j] = f[i - 1][j];}}cout << f[n][v] << endl;}return 0;}
0 0
- HDU 2602 Bone Collector
- hdu 2602 Bone Collector
- hdu 2602 Bone Collector
- hdu 2602 Bone Collector
- HDU 2602 - Bone Collector
- HDU 2602 Bone Collector
- hdu 2602 Bone Collector
- HDU 2602 Bone Collector
- hdu 2602 Bone Collector
- hdu 2602 Bone Collector
- Hdu 2602 - Bone Collector
- hdu 2602 Bone Collector
- hdu 2602 Bone Collector
- Hdu 2602 Bone Collector
- Hdu 2602 Bone Collector
- hdu 2602 Bone Collector
- hdu - 2602 - Bone Collector
- hdu 2602 Bone Collector
- 线程
- 线性表的链式存储与实现
- get方式请求转码
- Template模式
- 官方给的 JXLS 读取 excel 文件的例子
- Bone Collector HDU
- Kalman滤波器从原理到实现
- 不得不知的容器生态圈发展趋势
- 1055: 【数组的距离】
- 【Unity】Unity中实现全局管理类的几种方式
- git详细操作
- 3A DC/DC 降压芯片电路,开关电源
- jdbcTemplate query 方法的回调
- 石油大OJ 1023 问题 L: Pong’s Birds【概率Dp】