动态规划(二维背包问题):UVAoj 473

 Raucous Rockers 

You just inherited the rights to n previously unreleased songs recorded by the popular group Raucous Rockers. You plan to release a set of m compact disks with a selection of these songs. Each disk can hold a maximum of t minutes 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 included 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 values of n, t and m (integer numbers) followed by a line containing a list of the length of n songs, tex2html_wrap_inline43 ordered by the date they were written (Each tex2html_wrap_inline45 is between 1 and t minutes long, both inclusive, and tex2html_wrap_inline49 .)

 

Output

The output for each dataset consists of one integer indicating the number of songs that, following the above selection criteria will fit on m disks. Print a blank line between consecutive datasets.

 

Sample Input

 

2

10 5 3
3, 5, 1, 2, 3, 5, 4, 1, 1, 5

1 1 1
1

 

Sample Output

 

6

1

  题意不清啊,
  1. The songs will be recorded on the set of disks in the order of the dates they were written.

  这句话没有卵用,你一看错就真错了。

  

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 using namespace std;
 5 int n,m,t;
 6 int dp[1025][1025],tim[1025];
 7 
 8 int main()
 9 {
10     int T;
11     scanf("%d",&T);
12     while(T--)
13     {
14         scanf("%d%d%d",&n,&t,&m);
15         memset(dp,0,sizeof(dp));
16         for(int i=1;i<=n;i++){
17             if(i!=n)
18                 scanf("%d,",&tim[i]);
19             else
20                 scanf("%d",&tim[i]);    
21         }
22         
23         for(int i=1;i<=n;i++)
24             for(int j=m;j>=1;j--)
25                 for(int k=t;k>=tim[i];k--)
26                     dp[j][k]=max(dp[j][k],max(dp[j][k-tim[i]],dp[j-1][t])+1);
27     
28         printf("%d\n",dp[m][t]);
29         if(T)printf("\n");    
30     }
31         
32     return 0;
33 }

 

转载于:https://www.cnblogs.com/TenderRun/p/5259595.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值