uva473
| 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:
- The songs will be recorded on the set of disks in the order of the dates they were written.
- 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
这题说的是给了 一个序列的的歌曲播放的时间分别是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的更多相关文章
- [置顶] 刘汝佳《训练指南》动态规划::Beginner (25题)解题报告汇总
本文出自 http://blog.csdn.net/shuangde800 刘汝佳<算法竞赛入门经典-训练指南>的动态规划部分的习题Beginner 打开 这个专题一共有25题,刷完 ...
随机推荐
- php 实现 java com.sun.org.apache.xml.internal.security.utils.Base64 Byte数组加密
<?php function java_base64_encode($arr){ $str = ''; foreach ($arr as $key => $value) { $str .= ...
- Python 练习题:统计系统剩余内存
#!/usr/bin/env python #-*- coding:utf-8 -*- ''' 统计系统内存信息 ''' with open('/proc/meminfo') as fd: for l ...
- source insight 如何建工程--以及快捷方式查找调用函数方法
在source insight的view菜单中点出relation window,然后右键点relation window,选relation window properties,然后把view re ...
- IIS禁止xml文件访问
今天在出现数据库账号信息泄露的时候,突然想到xml文件里面放着很多信息,而且网页能够直接访问到,这就很有问题了 开始的时候,也在IIS网站那里看到请求筛选这个设置,开始还以为不能加呢,还是同事说的.
- 网络子系统45_ip协议tos处理
//ip报头tos字段,一个字节 // 二进制位:[0 1 2] [3] [4] [5] [6] [7] // 1.[0 1 2] 表示优先级: // 000 路由 // 001 优先级 // 010 ...
- MQTT-SN协议乱翻之简要介绍
前言 这一段时间在翻看MQTT-SN的协议,对针对不依赖于TCP传输的MQTT协议十分感兴趣,总是再想着这货到底是怎么定义的.一系列文章皆有MQTT-SN 1.2协议所拼装组成,原文档地址: MQTT ...
- 【BZOJ3935】Rbtree 树形DP
[BZOJ3935]Rbtree Description 给定一颗 N 个点的树,树上的每个点或者是红色,或者是黑色. 每个单位时间内,你可以任选两个点,交换它们的颜色. 出于某种恶趣味,你希望用最少 ...
- oracle的START WITH CONNECT BY PRIOR用法
转自:https://www.cnblogs.com/linjiqin/archive/2013/06/24/3152674.html Oracle 树操作(select…start with…con ...
- applicationContext.xml的文件位置就可以有两种默认实现
ContextLoaderListener的作用就是启动Web容器时,自动装配ApplicationContext的配置信息.因为它实现了ServletContextListener这个接口,在web ...
- matplotlib 散点图scatter
最近开始学习python编程,遇到scatter函数,感觉里面的参数不知道什么意思于是查资料,最后总结如下: 1.scatter函数原型 2.其中散点的形状参数marker如下: 3.其中颜色参数c如 ...