UVa 10465 - Homer Simpson

來源:互聯網
上載者:User

標籤:io   os   for   sp   on   時間   bs   as   ios   

題目:有兩種食物(數量無限)是Simpson喜歡的,每種食物都需要一個進食時間,現在他有時間t,

              問能最多吃多少個食物,時間盡量用完,用不完求最小浪費時間情況下的最多能吃的實物數量。

分析:dp,完全背包。放滿體積的背包,初始化除了f(0),均為 -oo,然後取正值即可。

說明:又見dp。

#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;int F[10001];int main(){int m,n,t,e;while (cin >> m >> n >> t) {for (int i = 1 ; i <= t ; ++ i)F[i] = -1000001;F[0] = 0;for (int i = m ; i <= t ; ++ i)if (F[i] < F[i-m]+1)F[i] = F[i-m]+1;for (int i = n ; i <= t ; ++ i)if (F[i] < F[i-n]+1)F[i] = F[i-n]+1;int e = t;while (F[e] < 0) -- e;cout << F[e];if (e == t) cout << endl;else cout << " " << t-e << endl;}return 0;}


UVa 10465 - Homer Simpson

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.