"Broken Gong Rock" band (Codevs 1444)

Source: Internet
Author: User

Title Description Description

You have just inherited the copyright of the <= N (1 n <= 20) song recorded by the popular "Broken Gong Rock" band. You are going to select some songs from which to release m (1 <= m <= 20) CD. Each CD can hold up to T (1 <= T <= 20) minutes of music and one song cannot be divided on two CDs.

Unfortunately you are a classical music fan, do not know how to determine the artistic value of these songs. So you decide to choose according to the following criteria:

1. Songs must appear on the CD in chronological order of creation.

2. Select the number of songs as much as you can.

Enter a description Input Description

First line: three integers: N, T, M.

Second line: n integers that represent the length of each song, in chronological order of creation.

Output description Output Description

An integer that represents the maximum number of songs that can be loaded into the M CD disc.

Sample input Sample Input

4 5 2

4 3 4 2

Sample output Sample Output

3

/*deformed knapsack problem f[j][k] indicates that the current song is loaded to the J CD, and the maximum number of songs that can be installed when installed in K capacity is f[j][k]=f[j][k-a[i]]+1 when the first J CD is installed, and when the second is not loaded, it should be loaded into the first j-1, that is f[ J][k]=f[j-1][t]+1. */#include<iostream>#include<cstdio>#include<algorithm>#defineM 22using namespacestd;intn,m,t;intT[m];intF[m][m];intMain () {scanf ("%d%d%d",&n,&t,&m);  for(intI=1; i<=n;i++) scanf ("%d",&T[i]);  for(intI=1; i<=n;i++)       for(intj=m;j>=1; j--)         for(intk=t;k>=t[i];k--) {F[j][k]=max (f[j][k],f[j][k-t[i]]+1); F[J][K]=max (f[j][k],f[j-1][t]+1); } printf ("%d", f[m][t]); return 0;}
View Code

"Broken Gong Rock" band (Codevs 1444)

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.