hdu 1712 ACboy needs your help 分組背包

來源:互聯網
上載者:User

/*<br />根據分析寫的代碼wrrong了,先放在這裡,如果哪位大牛會的話,麻煩幫忙修改下<br />把m天時間當成背包,每門課分成一類,每一類裡有m個物品<br />分別是上該門課j天得到的收穫,同一類物品只能選一個</p><p>這道題目太傻比了,輸入的是n * m 的, 而我輸入是n * n<br />可惡的sample居然是過的,悲劇</p><p>*/<br />#include <iostream><br />#include <algorithm><br />using namespace std;<br />int main()<br />{<br />int n , m;<br />int val[105][105];<br />int dp[105][105];<br />int temp[105];<br />while(cin >> n >> m)<br />{<br />if(n == 0 && m == 0)<br />break;<br />for(int i = 1; i <= n; i++)<br />for(int j = 1; j <= m; j++)//這裡太悲劇<br />cin >> val[i][j];<br />memset(dp, 0, sizeof(dp));<br />memset(temp, 0, sizeof(temp));</p><p>for(int i = 1; i <= n; i++)<br />for(int j = m; j >= 1; j--)<br />for(int k = 1; k <= j; k++)<br />//if(j >= k)<br />temp[j] = max(temp[j], temp[j - k] + val[i][k]);<br />cout << temp[m] << endl;<br />/* 但是還是不知道這個哪裡錯了<br />for(int i = 1; i <= n; i++)<br />for(int j = 1; j <= m; j++)<br />for(int k = 1; k <= j; k++)<br />dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - k] + val[i][k]);<br />cout<< dp[n][m] << endl;<br />*/</p><p>}<br />}

聯繫我們

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