Ultraviolet A 12563 Jin Ge Jin Qu hao (DP)

Source: Internet
Author: User

Ultraviolet A 12563 Jin Ge Jin Qu hao (DP)

 

 

Train of Thought: DP, with the idea of 01 backpack, each record the maximum number of songs at each time, and finally find the answer to satisfy the maximum number of songs, the maximum number of times

 

 

# Include

 
  
# Include

  
   
# Include using namespace std; const int N = 55; int T, n, t, sing [N], dp [11005]; int main () {int cas = 0; scanf (% d, & T); while (T --) {scanf (% d, & n, & t); for (int I = 0; I <n; I ++) scanf (% d, & sing [I]); sing [n ++] = 678; memset (dp,-1, sizeof (dp )); dp [0] = 0; for (int I = 0; I <n; I ++) {for (int j = min (t-1, 10000 ); j> = 0; j --) {if (dp [j]! =-1) dp [j + sing [I] = max (dp [j + sing [I], dp [j] + 1 );}} int ans1 = 0, ans2; for (int I = 11000; I> = 0; I --) {if (ans1 <dp [I]) {ans1 = dp [I]; ans2 = I ;}} printf (Case % d: % d, ++ cas, ans1, ans2) ;}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.