Ultraviolet A 10465-Homer Simpson

Source: Internet
Author: User

You can use a full backpack or greedy one.

Greedy words:

(1) if it happens to be T, update the maximum hamburger count (that is, the maximum number of A + B ).

(2) If t is not collected, the maximum value of A + B is updated when T-Max is the smallest.


Greedy method (0.024 S ):

 # include 
  
    # include 
   
     # include 
    
      # include 
     
       using namespace STD; int _ max; int main () {# ifdef test freopen ("input.txt", "r", stdin); # endif int M [2], T; while (scanf ("% d", & M [0], & M [1], & T )! = EOF) {int max1 = 0, max2 = 0, peer = 10000; For (INT I = 0; ++ I) {int sum = T-I * m [0]; If (sum <0) break; int num = sum/M [1]; int mod = sum % m [1]; If (! MoD) {If (max1 
       I + num) continue; max2 = I + num; peer = mod ;}} if (max1! = 0) printf ("% d \ n", max1); else printf ("% d \ n", max2, peer);} return 0 ;} 
     
    
   
  

DP (0.184 ):

 # include 
  
    # include 
   
     # include 
    
      # include 
     
       using namespace STD; int DP [10001]; const int INF = 0x3fffffff; int main () {# ifdef test freopen ("input.txt", "r", stdin ); # endif int M [2], T; while (scanf ("% d", & M [0], & M [1], & T )! = EOF) {for (INT I = 1; I <= T; ++ I) DP [I] =-INF; DP [0] = 0; for (INT I = 0; I <2; ++ I) for (Int J = m [I]; j <= T; ++ J) {int T = DP [J-M [I] + 1; if (DP [J] 
      
        = 0; -- I) if (DP [I]> = 0) {if (I = T) printf ("% d \ n ", DP [I]); else printf ("% d \ n", DP [I], t-I); break ;}return 0 ;}
      
     
    
   
  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.