Bone Collector【01背包】

F - Bone Collector

?HDU - 2602?

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 2?31).

Sample Input

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

Sample Output

14

?

AC代碼

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int n,v;
int c[1100],w[1100];
int f[1100];
int zeroone()
{for(int i=1;i<=n;i++)for(int j=v;j>=c[i];j--)f[j]=max(f[j],f[j-c[i]]+w[i]);return f[v];
}
int main()
{int num;cin>>num;while(num--){memset(f,0,sizeof(f));cin>>n>>v;for(int i=1;i<=n;i++)cin>>w[i];for(int i=1;i<=n;i++)cin>>c[i];cout<<zeroone()<<endl;}return 0;
}

?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/536414.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/536414.shtml
英文地址,請注明出處:http://en.pswp.cn/news/536414.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Gamma階段第八次scrum meeting

每日任務內容 隊員昨日完成任務明日要完成的任務張圓寧#91 用戶體驗與優化https://github.com/rRetr0Git/rateMyCourse/issues/91&#xff08;持續完成&#xff09;#91 用戶體驗與優化https://github.com/rRetr0Git/rateMyCourse/issues/91牛宇航#86 重置密碼的后端邏輯https:/…

【動態規劃】多重背包

問題 Q: 【動態規劃】多重背包 時間限制: 1 Sec 內存限制: 64 MB 提交: 112 解決: 49 [提交] [狀態] [討論版] [命題人:admin] 題目描述 張琪曼&#xff1a;“魔法石礦里每種魔法石的數量看起來是足夠多&#xff0c;但其實每種魔法石的數量是有限的。” 李旭琳&#xff1a;…

【動態規劃】完全背包問題

問題 O: 【動態規劃】完全背包問題 時間限制: 1 Sec 內存限制: 64 MB 提交: 151 解決: 71 [提交] [狀態] [討論版] [命題人:admin] 題目描述 話說張琪曼和李旭琳又發現了一處魔法石礦&#xff08;運氣怎么這么好&#xff1f;各種嫉妒羨慕恨啊&#xff09;&#xff0c;她們有…

springboot超級詳細的日志配置(基于logback)

前言 java web 下有好幾種日志框架&#xff0c;比如&#xff1a;logback&#xff0c;log4j&#xff0c;log4j2&#xff08;slj4f 并不是一種日志框架&#xff0c;它相當于定義了規范&#xff0c;實現了這個規范的日志框架就能夠用 slj4f 調用&#xff09;。其中性能最高的應該使…

【動態規劃】簡單背包問題II

問題 J: 【動態規劃】簡單背包問題II 時間限制: 1 Sec 內存限制: 64 MB 提交: 127 解決: 76 [提交] [狀態] [討論版] [命題人:admin] 題目描述 張琪曼&#xff1a;“為什么背包一定要完全裝滿呢&#xff1f;盡可能多裝不就行了嗎&#xff1f;” 李旭琳&#xff1a;“你說得…

Vue組件通信

前言 Vue組件之間的通信 其實是一種非常常見的場景 不管是業務邏輯還是前段面試中都是非常頻繁出現的 這篇文章將會逐一講解各個傳值的方式 不過在此之前 先來總結一下各個傳值方式吧 1.父組件向子組件傳值 > props2.子組件向父組件傳值 > $emit3.平級組件傳值 > 總線…

【動態規劃】0/1背包問題

問題 H: 【動態規劃】0/1背包問題 時間限制: 1 Sec 內存限制: 64 MB 提交: 152 解決: 95 [提交] [狀態] [討論版] [命題人:admin] 題目描述 張琪曼和李旭琳有一個最多能用m公斤的背包&#xff0c;有n塊魔法石&#xff0c;它們的重量分別是W1&#xff0c;W2&#xff0c;…&a…

貓哥教你寫爬蟲 005--數據類型轉換-小作業

小作業 程序員的一人飲酒醉 請運用所給變量&#xff0c;使用**str()**函數打印兩句話。 第一句話&#xff1a;1人我編程累, 碎掉的節操滿地堆 第二句話&#xff1a;2眼是bug相隨, 我只求今日能早歸 number1 1 number2 2 unit1 人 unit2 眼 line1 我編程累 line2 是bug相…

索引失效

轉載于:https://blog.51cto.com/11009785/2406488

棋盤問題【深搜】

棋盤問題 POJ - 1321 在一個給定形狀的棋盤&#xff08;形狀可能是不規則的&#xff09;上面擺放棋子&#xff0c;棋子沒有區別。要求擺放時任意的兩個棋子不能放在棋盤中的同一行或者同一列&#xff0c;請編程求解對于給定形狀和大小的棋盤&#xff0c;擺放k個棋子的所有可行…

python isinstance()

isinstanceisinstance(object, classinfo) 判斷實例是否是這個類或者object是變量 classinfo 是類型(tuple,dict,int,float) 判斷變量是否是這個類型 舉例&#xff1a; class objA: pass A objA() B a,v C a string print isinstance(A, objA) #注意該用法 print isinst…

P1303 A*B Problem 高精度乘法

復習了一下高精乘 #include<bits/stdc.h> using namespace std; const int maxn1e67; char a1[maxn],b1[maxn]; int a[maxn],b[maxn],c[maxn*10],lena,lenb,lenc,x; int main() {scanf("%s",a1);scanf("%s",b1);lenastrlen(a1);lenbstrlen(b1);for(i…

Catch That Cow【廣搜】

Catch That Cow POJ - 3278 Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0 ≤ N ≤ 100,000) on a number line and the cow is at a point K (0 ≤ K ≤ 100,000) on the same number l…

Go2Shell 已無法使用

在更新 Mac 系統時提醒了這個, 像我一樣對 Go2Shell 中毒的人來說, 這是無法忍受的。貌似 Go2Shell 沒有升級&#xff0c;沒有辦法&#xff0c;就直接找來了一個替代品。cd to, 下載入口如下&#xff1a;目前感覺良好。 轉載于:https://juejin.im/post/5cfe82e15188252b1b0366e…

Fliptile【搜索】

Fliptile POJ - 3279 Farmer John knows that an intellectually satisfied cow is a happy cow who will give more milk. He has arranged a brainy activity for cows in which they manipulate an M N grid (1 ≤ M ≤ 15; 1 ≤ N ≤ 15) of square tiles, each of which…

JS異步開發總結

1 前言 眾所周知&#xff0c;JS語言是單線程的。在實際開發過程中都會面臨一個問題&#xff0c;就是同步操作會阻塞整個頁面乃至整個瀏覽器的運行&#xff0c;只有在同步操作完成之后才能繼續進行其他處理&#xff0c;這種同步等待的用戶體驗極差。所以JS中引入了異步編程&…

迷宮問題【廣搜】

迷宮問題 POJ - 3984 定義一個二維數組&#xff1a; int maze[5][5] {0, 1, 0, 0, 0,0, 1, 0, 1, 0,0, 0, 0, 0, 0,0, 1, 1, 1, 0,0, 0, 0, 1, 0,}; 它表示一個迷宮&#xff0c;其中的1表示墻壁&#xff0c;0表示可以走的路&#xff0c;只能橫著走或豎著走&#xff0c;不能…

大蝦對51單片機入門的經驗總結

回想起當初學習AT89S52的日子還近在眼前:畢業后的第一年呆在親戚公司做了10個月設備管理.乏味的工作和繁雜的瑣事讓我郁悶不已.思考很久后終于辭職.投奔我的同學去了,開始并不曾想到要進入工控行業,知識想找一份電子類技術職業,至于什么職業我根本沒有目標可言.經過兩個多月的挫…

mac安裝cnpm

1.先安裝node node的下載地址&#xff1a;http://nodejs.cn/download/ 這個沒什么好說的&#xff0c;安裝完成后測試一下&#xff0c;在終端輸入&#xff1a;node -v 這時候就可以看到安裝的node版本號&#xff0c;再輸入&#xff1a;npm -v 這時候就會看到npm的版本號了 2.用n…

A計劃【廣搜】

A計劃 HDU - 2102 可憐的公主在一次次被魔王擄走一次次被騎士們救回來之后&#xff0c;而今&#xff0c;不幸的她再一次面臨生命的考驗。魔王已經發出消息說將在T時刻吃掉公主&#xff0c;因為他聽信謠言說吃公主的肉也能長生不老。年邁的國王正是心急如焚&#xff0c;告招天…