国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Bone Collector(01背包)

2019-11-08 02:50:46
字體:
來源:轉載
供稿:網友

Think 很明顯的01背包問題。。。

PRoblem Description 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 ?

Input The first line contain a integer T , the number of cases. 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. Output One integer per line representing the maximum of the total value (this number will be less than 231).

Example Input

1 5 10 1 2 3 4 5 5 4 3 2 1

Example Output 14

題目大意 : 1.第一行輸入T – T組數據 2.第二行N, M – 有N種骨頭 , 背包最大容量為M 3.每根骨頭的 價值 4.每根骨頭的體積 5.求 背包 的 最大價值 6.01背包

#include<bits/stdc++.h>using namespace std;int main() { int T; int v[1050]; int w[1050]; int dp[1050]; int i, j; int N, V; cin >> T; while(T --) { cin >> N >> V; for (i = 0;i <= N - 1; i ++) { cin >> v[i]; } for (i = 0;i <= N - 1; i ++) { cin >> w[i]; } memset(dp, 0, sizeof(dp)); for (i = 0;i <= N - 1;i ++) { for (j = V; j >= w[i];j --) { dp[j] = max(dp[j], dp[j - w[i]] + v[i]); } } cout << dp[V] <<endl; } return 0; }/***************************************************User name: Result: AcceptedTake time: 4msTake Memory: 172KBSubmit time: 2017-02-18 16:05:04****************************************************/
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 长沙县| 上杭县| 双鸭山市| 赤壁市| 房山区| 灵武市| 田林县| 南宫市| 磐石市| 永修县| 南乐县| 图们市| 紫阳县| 织金县| 曲水县| 仁寿县| 四子王旗| 旬阳县| 安国市| 海盐县| 新蔡县| 柏乡县| 沂源县| 新和县| 隆化县| 满洲里市| 鞍山市| 静安区| 安义县| 武义县| 汪清县| 淳化县| 阿克| 清徐县| 滁州市| 且末县| 驻马店市| 碌曲县| 八宿县| 望城县| 余干县|