Kaidul

11003

Sep 19th, 2013
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstdio>
  4. using namespace std ;
  5.  
  6. #define MaxN 1000
  7. #define MaxLoad 3000
  8. #define MaxWeight 3000
  9.  
  10. int main() {
  11. #ifndef ONLINE_JUDGE
  12.     freopen("input.txt", "r", stdin);
  13. #endif
  14.     int     boxs[ MaxLoad + MaxWeight + 1 ] = { 0 } ;
  15.     int     weight[ MaxN ] = { 0 } ;
  16.     int     load[ MaxN ] = { 0 } ;
  17.     int     n = 0 ;
  18.  
  19.     while( cin >> n && n != 0 ) {
  20.         for(int i = 0 ; i < n ; i++ ) {
  21.             cin >> weight[i] >> load[i];
  22.         }
  23.  
  24.         fill( boxs, boxs + MaxLoad + MaxWeight + 1, 0 ) ;
  25.         for(int i = n - 1 ; i >= 0 ; i-- ) {
  26.             for(int j = load[ i ] ; j >= 0 ; j-- ) {
  27.                 if( boxs[ j ] > 0 ) {
  28.                     boxs[ j + weight[i] ] = max(boxs[ j + weight[i] ], boxs[j] + 1);
  29.                 }
  30.             }
  31.             boxs[ weight[ i ] ] = max( boxs[ weight[i] ], 1) ;
  32.         }
  33.         cout << *( max_element(boxs, boxs + MaxLoad + MaxWeight + 1) ) << endl ;
  34.     }
  35.  
  36.     return 0 ;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment