Raucous Rockers

You just inherited the rights to N (1 <= N <= 20) previously unreleased songs recorded by the popular group Raucous Rockers. You plan to release a set of M (1 <= M <= 20) compact disks with a selection of these songs. Each disk can hold a maximum of T (1 <= T <= 20) 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 on the set of disks must appear in the order of the dates that they were written.
  • The total number of songs included will be maximized.

PROGRAM NAME: rockers

INPUT FORMAT

Line 1: Three integers: N, T, and M.
Line 2: N integers that are the lengths of the songs ordered by the date they were written.

SAMPLE INPUT (file rockers.in)

  1. 4 5 2
  2. 4 3 4 2

OUTPUT FORMAT

A single line with an integer that is the number of songs that will fit on M disks.

SAMPLE OUTPUT (file rockers.out)

  1. 3
  2.  
  3. ——————————————————————————
    一道连我这种蒟蒻都能做出来的dp
    dp(i,j)=dp(i-1,k)+packbag(v=t,k+1--j)
    i表示选了几个背包,j表示从前到后选了几首歌】
    【然后做一个背包,关于容量为t然后从k+1j之间选歌】
    【背包预处理应该会更快,然而在线处理复杂度够了而且绰绰有余】
  1. /*
  2. ID: ivorysi
  3. PROG: rockers
  4. LANG: C++
  5. */
  6. #include <iostream>
  7. #include <cstdio>
  8. #include <cstring>
  9. #include <algorithm>
  10. #include <queue>
  11. #include <set>
  12. #include <vector>
  13. #include <string.h>
  14. #define siji(i,x,y) for(int i=(x);i<=(y);++i)
  15. #define gongzi(j,x,y) for(int j=(x);j>=(y);--j)
  16. #define xiaosiji(i,x,y) for(int i=(x);i<(y);++i)
  17. #define sigongzi(j,x,y) for(int j=(x);j>(y);--j)
  18. #define inf 0x3f3f3f3f
  19. #define MAXN 400005
  20. #define ivorysi
  21. #define mo 97797977
  22. #define ha 974711
  23. #define ba 47
  24. #define fi first
  25. #define se second
  26. #define pii pair<int,int>
  27. using namespace std;
  28. typedef long long ll;
  29. int n,m,t;
  30. int song[];
  31. int getso[][];
  32. int f[];
  33. inline int max(int a,int b){return a>b?a:b;}
  34. int check(int b,int e) {
  35. if(e<b) return ;
  36. memset(f,,sizeof(f));
  37. siji(i,b,e) {
  38. gongzi(j,t,song[i]) {
  39. f[j]=max(f[j],f[j-song[i]]+);
  40. }
  41. }
  42. return f[t];
  43. }
  44. void solve() {
  45. scanf("%d%d%d",&n,&t,&m);
  46. siji(i,,n) scanf("%d",&song[i]);
  47. siji(i,,m) {
  48. siji(j,,n) {
  49. xiaosiji(k,,j) {
  50. getso[i][j]=max(getso[i][j],getso[i-][k]+check(k+,j));
  51. }
  52. }
  53. }
  54. printf("%d\n",getso[m][n]);
  55. }
  56. int main(int argc, char const *argv[])
  57. {
  58. #ifdef ivorysi
  59. freopen("rockers.in","r",stdin);
  60. freopen("rockers.out","w",stdout);
  61. #else
  62. freopen("f1.in","r",stdin);
  63. #endif
  64. solve();
  65. }
  1.  
  1.  

USACO 3.4 Raucous Rockers的更多相关文章

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

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

  2. USACO Section 3.4: Raucous Rockers

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

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

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

  4. [luoguP2736] “破锣摇滚”乐队 Raucous Rockers(DP)

    传送门 f[i][j]表示前i首歌放到前j个盘里最多能放多首 ntr[i][j]表示i~j中最多能放进一张盘中多少首歌 ntr数组可以贪心预处理出来. #include <cstdio> ...

  5. 递推DP UVA 473 Raucous Rockers

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

  6. USACO 完结的一些感想

    其实日期没有那么近啦……只是我偶尔还点进去造成的,导致我没有每一章刷完的纪念日了 但是全刷完是今天啦 讲真,题很锻炼思维能力,USACO保持着一贯猎奇的题目描述,以及尽量不用高级算法就完成的题解……例 ...

  7. USACO Training刷题记录 By cellur925

    Section 1.1 Your Ride Is Here 貌似没啥可说 Greedy Gift Givers 上来就想stl map映射,有两个坑:如果送给别人的人数为0,那么需要特判一下,防止整数 ...

  8. dp式子100个……

    1.        资源问题1-----机器分配问题F[I,j]:=max(f[i-1,k]+w[i,j-k]) 2.        资源问题2------01背包问题F[I,j]:=max(f[i- ...

  9. dp方程

    1.        资源问题1 -----机器分配问题 F[I,j]:=max(f[i-1,k]+w[i,j-k]) 2.        资源问题2 ------01背包问题   F[I,j]:=ma ...

随机推荐

  1. sql材料分级统计及汇总案例参考

    --第一步:根据系统编号.列.单价分组求和 select CLBH,DJ,sum(SL) as SL,sum(JE) as JE,Lie into #TempSZCMX from #ShouZhiCu ...

  2. asp.net MVC中的AppendTrailingSlash以及LowercaseUrls

    asp.net MVC中的AppendTrailingSlash以及LowercaseUrls asp.net MVC是一个具有极大扩展性的框架,可以在从Url请求开始直到最终的html的渲染之间进行 ...

  3. oracle导入数据

    oracle导入数据时候注意点: 1.imp system/admin@oracle9i file=E:\shujukuwenjian\2014-04-01.dmp fromuser=ptb_supe ...

  4. Step one : 熟悉HTML

    //H1 1 <html> <head> <title>BeiJing</title> </head> <body> <h ...

  5. Swift之函数语法详解

    函数 函数是用来完成特定任务的独立的代码块.你给一个函数起一个合适的名字,用来标识函数做什么,并且当函数需要执行的时候,这个名字会被“调用”. Swift 统一的函数语法足够灵活,可以用来表示任何函数 ...

  6. SOA的企业系统架构

    基于SOA的企业系统架构设计及IT治理日记 (引) TOGAF是一个架构框架,指导做企业架构的标准和方法,简而言之,是一种协助开发.验收.运行.使用和维护架构的工具,核心是架构开发方法(ADM)指导了 ...

  7. [转]A Faster UIWebView Communication Mechanism

    ref:http://blog.persistent.info/2013/10/a-faster-uiwebview-communication.html Use location.hash or t ...

  8. 随便讲讲XSS攻击

    作为一个前端工程师,XSS漏洞不应该只是安全部门的工作.在项目上马的时候就应该对可能涉及的安全问题有所预防才是有一个好前端.- -   什么是XSS •跨站脚本攻击(Cross-site script ...

  9. IOS学习之路十(仿人人滑动菜单Slide-out Sidebar Menu)

    最近滑动菜单比较流行,像facebook和人人等都在使用滑动菜单,今天做了一个小demo大体效果如下: 这次用了一个开源的项目ECSlidingViewController这个也是一个挺著名的托管在G ...

  10. spring.net AOP初探

    AOP是什么? 面向切面编程,在OO中有一个开放关闭原则,及对修改关闭,对扩展开放.AOP可以说是设计模式的集合加强版,使用代理.工厂.策略等等模式,来实现方法的结合.这样说还比较模糊,我们先往下看. ...