hdoj 2602 Bone Collector 【01背包】

來源:互聯網
上載者:User

標籤:

意甲冠軍:給出的數量和袋骨骼的數,然後給每塊骨骼的價格值和音量。尋求袋最多可容納骨骼價格值

難度;這個問題是最基本的01背包稱號,不知道的話,推薦看《背包9說話》

AC by SWS

主題連結 http://acm.hdu.edu.cn/showproblem.php?pid=2602

代碼:

#include<stdio.h>#include<string.h>typedef struct{int w, v; }str;str s[1005];int dp[1005];int main(){int n, m, t, i, j;scanf("%d", &t);while(t --){scanf("%d%d", &n, &m);for(i = 0; i < n; i ++)scanf("%d", &s[i].w);for(i = 0; i < n; i ++)scanf("%d", &s[i].v);memset(dp, 0, sizeof(dp));for(i = 0; i < n; i ++)for(j = m; j >= s[i].v; j --){if(dp[j]<dp[j-s[i].v] + s[i].w) dp[j] = dp[j-s[i].v]+s[i].w;}printf("%d\n", dp[m]);}return 0;}


著作權聲明:本文博主原創文章,部落格,未經同意不得轉載。

hdoj 2602 Bone Collector 【01背包】

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.