hdu--2844--多重背包

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   io   資料   for   

真爽啊 打完一把絕對carry的亞索 來做這題 一發AC=-=

touch  me

這題 反正資料很大 不用二進位拆分 肯定tle的

反正 二進位拆分 很簡單的啊 不會的 現在看我代碼 學下就好了。。

 1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4  5 const int size = 100010; 6 int temp[110]; 7 int val[10010]; 8 bool dp[size]; 9 10 int main()11 {12     cin.sync_with_stdio(false);13     int i , j , n , m , cnt , num , ans;14     while( cin >> n >> m && (n||m) )15     {16         memset( dp , false , sizeof(dp) );17         ans = cnt = 0;18         for( i = 1 ; i<=n ; i++ )19         {20             cin >> temp[i];21         }22         for( i = 1 ; i<=n ; i++ )23         {24             cin >> num;25             for( j = 1 ; j<=num ; j<<=1 )26             {27                 val[cnt++] = temp[i] * j;28                 num -= j;29             }30             if( num )31                 val[cnt++] = temp[i] * num;32         }33         dp[0] = true;34         for( i = 0 ; i<cnt ; i++ )35         {36             for( j = m ; j>=val[i] ; j-- )37             {38                 if( dp[j-val[i]] )39                 {40                     dp[j] = true;41                 }42             }43         }44         for( i = 1 ; i<=m ; i++ )45         {46             if( dp[i] )47                 ans ++;48         }49         cout << ans << endl;50     }51     return 0;52 }
View Code

 

聯繫我們

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