Uva473

Source: Internet
Author: User

 

Raucous Rockers

You just inherited the rightsNPreviusly unreleased songs recorded by the popular group Raucous Rockers. You plan to release a setMCompact disks with a selection of these songs. Each disk can hold a maximumTMinutes of music, and a song can not overlap from one disk to another. since you are a classical music fan and have no way to judge the artistic merits of these songs, you decide on the following criteria for making the selection:

  1. The songs will be recorded on the set of disks in the order of the dates they were written.
  2. The total number of songs encoded Ded will be maximized.
Input

The input consists of several datasets. the first line of the input indicates the number of datasets, then there is a blank line and the datasets separated by a blank line. each dataset consists of a line containing the valuesNTAndM(Integer numbers) followed by a line containing a list of the lengthNSongs, ordered by the date they were written (Each is between 1 and t minutes long, both hybrid, and .)

 

Output

The outputFor each dataset consists of one integer indicating the number of songs that, following the above selection criteria will fit onMDisks. Print a blank line between consecutive datasets.

 

Sample Input

 

210 5 33, 5, 1, 2, 3, 5, 4, 1, 1, 51 1 11

 

Sample Output

 

61
This question is to give a sequence of songs playing time is t0 --- TN-1 and then m disk each disk can store T minutes of songs, you cannot store a song on two or more disks. Calculate the maximum number of songs that can be stored on m disks.
Dp [I] [j] [k] indicates the maximum value of the k position of the song I on the disk of j, when he is placed in the first position, he needs to determine the result obtained from the end of the previous disk. Otherwise, he uses a 01 backpack for each disk. Because of the large data size, he uses a rolling array.
# Include <iostream> # include <cstdio> # include <algorithm> # include <string. h> using namespace std; const int maxn = 105; int dp [maxn] [maxn]; int t [maxn], n, T, m; int main () {int cas; scanf ("% d", & cas); for (int cc = 1; cc <= cas; ++ cc) {scanf ("% d", & n, & T, & m); memset (dp, 0, sizeof (dp )); for (int I = 0; I <n; ++ I) {int d; scanf ("% d % * c", & d); for (int j = m; j> = 1; j --) for (int k = T; k> = d; -- k) {dp [j] [k] = max (dp [j] [k], dp [j-1] [T] + 1 ); dp [j] [k] = max (dp [j] [k], dp [j] [k-d] + 1) ;}} if (cc = cas) printf ("% d \ n", dp [m] [T]); else printf ("% d \ n", dp [m] [T]);} return 0 ;}
View Code

 



Uva473

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.