UVA-12563 Jin Ge jin Qu hao (01 backpack)

Source: Internet
Author: User

First of all, the test instructions to read first, rather than to see the 01 knapsack problem began to knock.

Main topic:
If you ask a Mac: "You in the KTV will sing the songs have those", the answer may be included Leo Ku "Jin song", generally speaking, KTV will not in time to be sung song to cut off, but will wait for it to put out, for example, there are 15 seconds to sing a song 2 minutes, then actually sang more than 105 seconds. But singing "The Divine Comedy" "Jin Song" is equivalent to singing for more than 663 seconds.
Now ask you to sing as many songs as possible, and sing the time as long as possible.

Ideas:

01 Backpack Thinking, each time the maximum number of songs, the last to find the answer first to meet the maximum number of songs, and then meet the most time.

#include <cstdio> #include <cstring> #include <algorithm>using namespace std;const int N = 55;const int M Ax_time = 100005;int song[n],dp[max_time];int n,t;int main () {int t,cas = 1;SCANF ("%d", &t), while (t--) {scanf ("%d%d", &N,&T); for (int i = 0; i < n; i++) {scanf ("%d", &song[i]);} Memset (Dp,-1,sizeof (DP));DP [0] = 0;for (int i = 0; i < n; i++) {for (int j = min (t-1,max_time); J >= Song[i]; j--) {i F (dp[j-song[i]]! =-1) dp[j] = max (dp[j],dp[j-song[i]]+1);}} int MAXN = 0, time;for (int i = max_time-1; I >= 0; i--) {if (Maxn < dp[i]+1) {MAXN = Dp[i]+1;time = i;}} printf ("Case%d:%d%d\n", Cas++,maxn,time + 678);} return 0;}


UVA-12563 Jin Ge jin Qu hao (01 backpack)

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.