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. 第七篇:Logistic回归分类算法原理分析与代码实现

    前言 本文将介绍机器学习分类算法中的Logistic回归分类算法并给出伪代码,Python代码实现. (说明:从本文开始,将接触到最优化算法相关的学习.旨在将这些最优化的算法用于训练出一个非线性的函数 ...

  2. LVS+keeplived+nginx+tomcat高可用、高性能jsp集群

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://kerry.blog.51cto.com/172631/557749 #!/bin ...

  3. Mybatis中的foreach

    <delete id="deleteByParam"> DELETE FROM YZ_SECURITIES_CURRENCY WHERE ID IN <forea ...

  4. linux 提示符>怎样退出

    在linux(Red Hat)字符界面下,不小心输入了上漂号 ’ ,结果命令提示符变成了>,然后在q.exit.ctrl+c.ctrl+z都回不去了,不知道怎么回到#的命令提示符?   表示ct ...

  5. 【整理】Virtualbox中的网络类型(NAT,桥接等),网卡,IP地址等方面的设置

    之前是把相关的内容,放到: [已解决]实现VirtualBox中的(Guest OS)Mac和主机(Host OS)Win7之间的文件和文件夹共享 中的,现在把关于网络配置方面内容,单独提取出来,专门 ...

  6. 微信Android热补丁实践演进之路

    版权声明:本文由张绍文原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/81 来源:腾云阁 https://www.qclou ...

  7. SPOJ - DQUERY

    题目链接:传送门 题目大意:一个容量 n 的数组, m次询问,每次询问 [x,y]内不同数的个数 题目思路:主席树(注意不是权值线段树而是位置线段树) 也就是按一般线段树的逻辑来写只是用主席树实现而已 ...

  8. flask框架实战项目架构

    一.项目架构: 研习了多天flask,今天终于按照标准流程写了一个实验demo,并实现了ORM调用,一起喜欢自己写原生SQL.废话不多说,来看项目文件结构 mysite/ ./config/ defa ...

  9. C++ XML 序列化器

    http://www.cppblog.com/xlshcn/archive/2007/11/21/cppxmlserializer.html

  10. 【BZOJ2300】[HAOI2011]防线修建 set维护凸包

    [BZOJ2300][HAOI2011]防线修建 Description 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可 ...