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, ordered by the date they were written (Each is between 1 and t minutes long, both inclusive, and .)

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.

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

  

 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n,m,t;
int dp[][],tim[]; int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&t,&m);
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++){
if(i!=n)
scanf("%d,",&tim[i]);
else
scanf("%d",&tim[i]);
} for(int i=;i<=n;i++)
for(int j=m;j>=;j--)
for(int k=t;k>=tim[i];k--)
dp[j][k]=max(dp[j][k],max(dp[j][k-tim[i]],dp[j-][t])+); printf("%d\n",dp[m][t]);
if(T)printf("\n");
} return ;
}

动态规划(二维背包问题):UVAoj 473的更多相关文章

  1. 【动态规划/二维背包问题】mr355-三角形牧场

    应该也是USACO的题目?同样没有找到具体出处. [题目大意] 和所有人一样,奶牛喜欢变化.它们正在设想新造型牧场.奶牛建筑师Hei想建造围有漂亮白色栅栏的三角形牧场.她拥有N(3≤N≤40)块木板, ...

  2. C语言-二维背包问题

    二维费用背包问题 问题: 二维费用的背包问题是指:对于每件物品,具有两种不同的费用:选择这件物品必须同时付出这两种代价:对于每种代价都有 一个可付出的最大值(背包容量).问怎样选择物品可以得到最大的价 ...

  3. 【CodeForces】713 D. Animals and Puzzle 动态规划+二维ST表

    [题目]D. Animals and Puzzle [题意]给定n*m的01矩阵,Q次询问某个子矩阵内的最大正方形全1子矩阵边长.n,m<=1000,Q<=10^6. [算法]动态规划DP ...

  4. 【洛谷】【动态规划(二维)】P1508 Likecloud-吃、吃、吃

    [题目描述:] 正处在某一特定时期之中的李大水牛由于消化系统比较发达,最近一直处在饥饿的状态中.某日上课,正当他饿得头昏眼花之时,眼前突然闪现出了一个n*m(n and m<=200)的矩型的巨 ...

  5. [ACM_动态规划] POJ 1050 To the Max ( 动态规划 二维 最大连续和 最大子矩阵)

    Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any ...

  6. 【洛谷】【动态规划/二维背包】P1855 榨取kkksc03

    [题目描述:] ... (宣传luogu2的内容被自动省略) 洛谷的运营组决定,如果...,那么他可以浪费掉kkksc03的一些时间的同时消耗掉kkksc03的一些金钱以满足自己的一个愿望. Kkks ...

  7. hdu2159FATE(二维背包)

    http://acm.hdu.edu.cn/showproblem.php?pid=2159 Problem Description 最近xhd正在玩一款叫做FATE的游戏,为了得到极品装备,xhd在 ...

  8. SPOJ 181 - Scuba diver 二维背包

    潜水员要潜水,给出n个气缸(1<=n<=1000),每个气缸中有氧气量为ti,氮气量为ai,气缸重量为wi(1<=ti<=21,1<=ai<=79,1<=wi ...

  9. 动态规划:HDU3496-Watch The Movie(二维费用的背包问题)

    Watch The Movie Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) ...

随机推荐

  1. Sql Server 中事务(begin tran/commit tran/rollback tran)的用法

    ALTER PROCEDURE [dbo].[Proc_Test_commit1]     @result int output, --成功 1; 失败 0     @message nvarchar ...

  2. J2EE 读取文件路径

    在J2ee中实现java类读取webcontent/web-inf/config.xml的实现代码 ,其中../config.xml相对于classes的路径 java.net.URL url = t ...

  3. oracle 字符串切割成结果集方法

    oracle字符串切割几种方式 方法一: SELECT COLUMN_VALUE FROM TABLE(SYS.ODCIVARCHAR2LIST('1','2','3','4','5')); 方法二: ...

  4. 在ec2上创建root用户,并使用root 通过Xshell远程登录aws云服务器

    1.根据官网提供的方法登录连接到EC2服务器(官网推荐windows用户使用PUTTY连接) 2. 创建root的密码,输入如下命令: sudo passwd root 3.然后会提示你输入new p ...

  5. (九)打印机驱动设置—USB接口的设置

    佳博打印机代理商淘宝店https://shop107172033.taobao.com/index.htm?spm=2013.1.w5002-9520741823.2.Sqz8Pf 在此店购买的打印机 ...

  6. Swift中可选类型(Optional)的用法 以及? 和 ! 的区别 (转载博客,知识分享)

    本文转载自:代码手工艺人的博客,原文名称:Swift之 ? 和 ! Swift语言使用var定义变量,但和别的语言不同,Swift里不会自动给变量赋初始值,也就是说变量不会有默认值,所以要求使用变量之 ...

  7. Python:运算符

    #!/usr/bin/python3 #运算符 #算术运算符 print("算术运算符:","+ - * / % **(幂) //(取整)") #比较运算符 p ...

  8. 百度地图API地址转换成经纬度

    public class LngAndLatUtil { public static Map<String,Double> getLngAndLat(String address){ Ma ...

  9. SGU 101.Domino (欧拉路)

    时间限制: 0.5 sec 空间限制: 4096 KB 描述 多米诺骨牌,一种用小的方的木块或其他材料,每个都被一些点在面上标记,这些木块通常被称为骨牌.每个骨牌的面都被一条线分成两个   方形,两边 ...

  10. c++ undefined reference to mysqlinit

    Solved g++ $(mysql_config --cflags) file.cpp -o filename $(mysql_config --libs)