Sicily 1146 Medicine (dynamic Regulation)

Source: Internet
Author: User

Playing code does not go heart will fall in the pit.

Below is the code:

1 //1146. Drug-collecting2 //t = Total time3 //m indicates the number of herbs4 //W indicates the time of the drug adoption5 //v denotes herbal value6#include <iostream>7 using namespacestd;8 9 #defineMAX (A, b) a>b?a:bTen  One intMaxValue (intW[],intV[],intMintt) { A     intmax[m+1][t+1]; -      for(inti =0; I <= t; i++) { -         if(i>=w[1]) max[1][i] = v[1];//I was just beginning to make the w[1 here] w[i]. Next time to hit the code must go heart.  the         Elsemax[1][i] =0; -     } -      for(inti =2; I <= m; i++) { -          for(intj =0; J <= T; J + +) { +             if(J<w[i]) max[i][j] = max[i-1][j]; -             Else { +MAX[I][J] = MAX (max[i-1][J], (max[i-1][j-w[i]]+v[i])); A             } at         } -     } -     returnMax[m][t]; - } -  - intMain () { in     intT, M; -Cin>>t>>m; to     intw[m+1], v[m+1]; +      for(inti =1; I <= m; i++) cin>>w[i]>>V[i]; -Cout<<maxvalue (w,v,m,t) <<Endl; the     return 0; *}

Sicily 1146 Medicine (dynamic Regulation)

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.