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 nt 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
这题说的是给了 一个序列的的歌曲播放的时间分别是t0---tn-1 然后 有m个磁盘 每个磁盘可以存T分钟的歌曲,不能有一首歌放在两个磁盘或者以上,求m个磁盘所能容下的最多歌曲的个数
dp[i][j][k] 表示 第i首歌放在j的磁盘k位置的最大值 , 当他放在第一个位置时需要特判一下从上一个磁盘的末尾得到,否者对每个磁盘采用01背包,由于数据大采用滚动数组
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
using namespace std;
const int maxn=;
int dp[maxn][maxn];
int t[maxn],n,T,m;
int main()
{
int cas;
scanf("%d",&cas);
for(int cc = ;cc<=cas; ++cc){
scanf("%d%d%d",&n,&T,&m);
memset(dp,,sizeof(dp));
for(int i=; i<n; ++i){
int d;
scanf("%d%*c",&d);
for(int j=m; j>=; j--)
for(int k=T; k>=d; --k){
dp[j][k]=max(dp[j][k],dp[j-][T]+);
dp[j][k]=max(dp[j][k],dp[j][k-d]+);
}
}
if(cc==cas) printf("%d\n",dp[m][T]);
else printf("%d\n\n",dp[m][T]);
}
return ;
}
												

uva473的更多相关文章

  1. [置顶] 刘汝佳《训练指南》动态规划::Beginner (25题)解题报告汇总

    本文出自   http://blog.csdn.net/shuangde800 刘汝佳<算法竞赛入门经典-训练指南>的动态规划部分的习题Beginner  打开 这个专题一共有25题,刷完 ...

随机推荐

  1. shell基础(六)--字符串和数组

    对文本处理,单独用shell来处理还是比较薄弱.所以shell就引用了awk and sed这两个命令.我们今天不说这个 一 字符串  字符串是shell编程中最常用最有用的数据类型,因为你定义一个变 ...

  2. Hash表 hash table 又名散列表

    直接进去主题好了. 什么是哈希表? 哈希表(Hash table,也叫散列表),是根据key而直接进行访问的数据结构.也就是说,它通过把key映射到表中一个位置来访问记录,以加快查找的速度.这个映射函 ...

  3. 【RF库Collections测试】Create Dictionary

    Name:Create DictionarySource:Collections <test library>Arguments:[ *key_value_pairs ]

  4. 运行 3ds Max 时出现的性能问题

          运行 3ds Max 时性能减慢或迟缓通常是由于视频配置冲突或内存分配问题引起的.关于性能问题的一大难点在于缩小范围确定问题原因.以下是一些限制 3ds Max 操作的常见情形,以及纠正这 ...

  5. Memcache命令及参数用法

    Memcache命令:在linux下: # /usr/local/bin/memcached -d -m 128 -u root -l 192.168.0.10 -p 12121 -c 256 -P ...

  6. 小程序的movable-view怎么持续移动

    在小程序的官方例子中,点击按钮以后的movable-view只是挪动了一次(链接:https://mp.weixin.qq.com/debug/wxadoc/dev/component/movable ...

  7. web基础---->Fileupload文件的上传

    这里我们介绍文件上传的知识,使用的是apache的Commons FileUpload框架. 文件上传的使用 项目的部分结构如下: 一.使用Commons FileUpload的上传功能,我们需要引入 ...

  8. js嵌套轮播图

    $(function(){ var navLi = $(".top_nav").find("li"), conDiv = $(".top_con&qu ...

  9. Python GUI--Tkinter实践

    之前写了Testlink自动执行程序,现使用Tkinter加上GUI试试,想要实现如下图功能 可以实现通过选择要执行的url及报告url自动执行用例,或可以直接写报告结果内容 因项目原因,只列出部分代 ...

  10. wamp环境解决局域网不能访问的问题!

    安装好wamp后,想用手机通过局域访问电脑上wamp下的网页,结果出现如下提示403错误: 第一步:找到 conf 这个文件: 找到下图中红色方框中的onlineoffline tag - don’t ...