传送门

f[i][j]表示前i首歌放到前j个盘里最多能放多首

ntr[i][j]表示i~j中最多能放进一张盘中多少首歌

ntr数组可以贪心预处理出来。

#include <cstdio>
#include <iostream>
#include <algorithm>
#define N 21
#define max(x, y) ((x) > (y) ? (x) : (y)) int n, t, m;
int a[N], b[N], ntr[N][N], f[N][N];
//f[i][j]表示前i首歌放到前j个盘里最多能放多首
//ntr[i][j]表示i~j中最多能放进一张盘中多少首歌 inline int read()
{
int x = 0, f = 1;
char ch = getchar();
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
return x * f;
} inline void init()
{
int i, j, k, sum, cnt;
for(i = 1; i <= n; i++)
for(j = i; j <= n; j++)
{
sum = cnt = 0;
for(k = i; k <= j; k++) b[k] = a[k];
std::sort(b + i, b + j + 1);
for(k = i; k <= j; k++)
if(sum + b[k] <= t)
{
cnt++;
sum += b[k];
}
ntr[i][j] = cnt;
}
} int main()
{
int i, j, k;
n = read();
t = read();
m = read();
for(i = 1; i <= n; i++) a[i] = read();
init();
for(i = 1; i <= n; i++)
for(j = 1; j <= m; j++)
for(k = 0; k < i; k++)
f[i][j] = max(f[i][j], f[k][j - 1] + ntr[k + 1][i]);
printf("%d\n", f[n][m]);
return 0;
}

  

[luoguP2736] “破锣摇滚”乐队 Raucous Rockers(DP)的更多相关文章

  1. 洛谷P2736 “破锣摇滚”乐队 Raucous Rockers

    P2736 "破锣摇滚"乐队 Raucous Rockers 21通过 52提交 题目提供者该用户不存在 标签USACO 难度普及+/提高 提交  讨论  题解 最新讨论 暂时没有 ...

  2. P2736 “破锣摇滚”乐队 Raucous Rockers

    题目描述 你刚刚继承了流行的“破锣摇滚”乐队录制的尚未发表的N(1 <= N <= 20)首歌的版权.你打算从中精选一些歌曲,发行M(1 <= M <= 20)张CD.每一张C ...

  3. Codevs 1444 “破锣摇滚”乐队

    1444 “破锣摇滚”乐队   题目描述 Description 你刚刚继承了流行的“破锣摇滚”乐队录制的尚未发表的N(1 <= N <= 20)首歌的版权.你打算从中精选一些歌曲,发行M ...

  4. “破锣摇滚”乐队(codevs 1444)

    题目描述 Description 你刚刚继承了流行的“破锣摇滚”乐队录制的尚未发表的N(1 <= N <= 20)首歌的版权.你打算从中精选一些歌曲,发行M(1 <= M <= ...

  5. USACO 3.4 Raucous Rockers

    Raucous Rockers You just inherited the rights to N (1 <= N <= 20) previously unreleased songs ...

  6. 递推DP UVA 473 Raucous Rockers

    题目传送门 题意:n首个按照给定顺序存在m张光盘里,每首歌有播放时间ti,并且只能完整的存在一张光盘里,问最多能存几首歌 分析:类似01背包和完全背包,每首歌可存可不存,存到下一张光盘的情况是当前存不 ...

  7. USACO Section 3.4: Raucous Rockers

    简单的dfs题目 /* ID: yingzho1 LANG: C++ TASK: rockers */ #include <iostream> #include <fstream&g ...

  8. DP擎天

    DP! 黄题: 洛谷P2101 命运石之门的选择 假装是DP(分治 + ST表) CF 982C Cut 'em all! 树形贪心 洛谷P1020 导弹拦截 单调队列水题 绿题: 洛谷P1594 护 ...

  9. DP小题集

    P2736 "破锣摇滚"乐队 Raucous Rockers 你刚刚继承了流行的"破锣摇滚"乐队录制的尚未发表的N(1 <= N <= 20)首歌的 ...

随机推荐

  1. 【学习笔记】后端中的MVC和前端MVVM的关系

  2. Kali部署openvas初探与实践

    openvas安装 1.我用的清华大学的源,所以我把/etc/apt/source.list中下入如下源地址 #清华大学deb http://mirrors.tuna.tsinghua.edu.cn/ ...

  3. js实现跨域的方法

    由于同源策略的限制,XMLHttpRequest只允许请求当前源(包含域名.协议.端口)的资源. json与jsonp的区别:    JSON是一种数据交换格式,而JSONP是一种依靠开发人员创造出的 ...

  4. centos 6.2用yum安装中文输入法

    centos 6.2用yum安装中文输入法 1.su root 2.yum install "@Chinese Support" 3.exit 4.回到桌面,system-> ...

  5. 封装addClass 、 removeClass

    <script> window.onload = function() { var oDiv = document.getElementById('div1'); var oDiv2 = ...

  6. 样式化复选框(Styling Checkbox)

    原理:https://www.tuicool.com/articles/y67jee 表现:http://www.freejs.net/demo/381/index.html https://www. ...

  7. 判断请求是否为ajax

    判断请求是否为ajax 转载:http://www.cnblogs.com/tony-jingzhou/archive/2012/07/30/2615612.html x-requested-with ...

  8. CPP-基础:inline

    背景: 在C&C++中 一.inline关键字用来定义一个类的内联函数,引入它的主要原因是用它替代C中表达式形式的宏定义. 表达式形式的宏定义一例: #define ExpressionNam ...

  9. Visual Odometry

    http://www.cvlibs.net/datasets/kitti/eval_odometry.php

  10. Piston Pump Manufacturers - Mobile Cartridge Piston Pump: Advantages

    The    Piston Pump Manufacturers   states that the operation of any piston pump is based on the rela ...