Va 12563 (01 backpack) jin Ge Jin Qu Hao

Source: Internet
Author: User
Tags define local

So the water's 01 backpack actually made me wa seven times.

I started to understand the incorrect question and reversed the primary-secondary relationship. The most important premise is the total number of tracks, followed by the longest total time of songs.

Question:

There is still a t second left in the KTV room. You can select several songs from N favorite songs (each song can only be sung once and it must be sung once ), then at least one second is left to sing the first 678 second song.

If the total number of tracks is the most, try to make the total time of the song the longest.

Analysis:

The given time is T, In the T-1 seconds for 01 backpack, num [I] to record the remaining time is I can be the maximum length of the track, if the tracks are the same but also to record the maximum time.

 

 1 //#define LOCAL 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5 using namespace std; 6  7 const int maxn = 10000; 8 int a[55], dp[maxn], num[maxn]; 9 10 int main(void)11 {12     #ifdef LOCAL13         freopen("12563in.txt", "r", stdin);14     #endif15 16     int T;17     scanf("%d", &T);18     for(int kase = 1; kase <= T; ++kase)19     {20         int n, t;21         scanf("%d%d", &n, &t);22         t--;23         for(int i = 0; i < n; ++i)24         {25             scanf("%d", &a[i]);26             if(a[i] > 180)    a[i] = 180;27         }28         memset(dp, 0, sizeof(dp));29         memset(num, 0, sizeof(num));30         for(int i = 0; i < n; ++i)31             for(int j = t; j >= a[i]; --j)32             {33                 if(num[j] < num[j-a[i]] + 1)34                 {35                     num[j] = num[j-a[i]] + 1;36                     dp[j] = dp[j-a[i]] + a[i];37                 }38                 else if(num[j] == num[j-a[i]] + 1)39                 {40                     dp[j] = max(dp[j], dp[j-a[i]] + a[i]);41                 }42             }43         printf("Case %d: %d %d\n", kase, num[t]+1, dp[t]+678);44     }45 46     return 0;47 }
Code Jun

 

Va 12563 (01 backpack) jin Ge Jin Qu Hao

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.