紫书P274

题意:输入N首歌曲和最后剩余的时间t,问在保证能唱的歌曲数目最多的情况下,时间最长;最后必唱《劲歌金曲》

所以就在最后一秒唱劲歌金曲就ok了,背包容量是t-1,来装前面的歌曲,设两个Time求时间,cnt是数量

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
const int MAX = 10000;
int cnt[MAX],Time[MAX],song[MAX];
int main()
{
int n,t;
int tase,num = 0;
scanf("%d", &tase);
while( tase-- )
{
scanf("%d%d", &n, &t);
for(int i = 1; i <= n; i++)
scanf("%d", &song[i]);
int v = t - 1;
memset(cnt, 0, sizeof(cnt));
memset(Time, 0, sizeof(Time));
for(int i = 1; i <= n; i++)
{
for(int j = v; j >= song[i]; j--)
{
if(cnt[j] < cnt[j - song[i]] + 1) //选择第i个时的数量多
{
cnt[j] = cnt[j - song[i]] + 1;
Time[j] = Time[j - song[i]] + song[i];
}
else if(cnt[j] == cnt[j - song[i]] + 1) //在数量相等的情况下,更新时间
{
if(Time[j] < Time[j - song[i]] + song[i])
Time[j] = Time[j - song[i]] + song[i];
}
}
}
int res =678 + Time[v];
printf("Case %d: %d %d\n",++num, cnt[v] + 1, res);
}
return 0;
}

  

UVA12563Jin Ge Jin Qu hao(01背包)的更多相关文章

  1. UVA - 12563 Jin Ge Jin Qu hao (01背包)

    InputThe first line contains the number of test cases T (T ≤ 100). Each test case begins with two po ...

  2. UVA12563-Jin Ge Jin Qu hao(动态规划基础)

    Problem UVA12563-Jin Ge Jin Qu hao Accept: 642  Submit: 7638Time Limit: 3000 mSec Problem Descriptio ...

  3. UVa12563- Jin Ge Jin Qu hao

    思路一定要清晰! /* * Author: Bingo * Created Time: 2014/12/25 3:45:35 * File Name: uva12563.cpp */ #include ...

  4. UVA 12563 "Jin Ge Jin Qu hao" (背包)

    传送门 debug了好一会,突然发现,输出错了,emmm......... 明天再写debug历程: (PS:ipad debug是真的繁琐) 题意: 题解: 尽管题干中给的 t 的范围很大,但是 t ...

  5. UVA Jin Ge Jin Qu hao 12563

    Jin Ge Jin Qu hao (If you smiled when you see the title, this problem is for you ^_^) For those who ...

  6. 12563 - Jin Ge Jin Qu hao——[DP递推]

    (If you smiled when you see the title, this problem is for you ^_^) For those who don’t know KTV, se ...

  7. 12563 Jin Ge Jin Qu hao

    • Don’t sing a song more than once (including Jin Ge Jin Qu). • For each song of length t, either si ...

  8. UVa 12563 (01背包) Jin Ge Jin Qu hao

    如此水的01背包,居然让我WA了七次. 开始理解错题意了,弄反了主次关系.总曲目最多是大前提,其次才是歌曲总时间最长. 题意: 在KTV房间里还剩t秒的时间,可以从n首喜爱的歌里面选出若干首(每首歌只 ...

  9. Jin Ge Jin Qu hao UVA - 12563 01背包

    题目:题目链接 思路:由于t最大值其实只有180 * 50 + 678,可以直接当成01背包来做,需要考虑的量有两个,时间和歌曲数,其中歌曲优先级大于时间,于是我们将歌曲数作为背包收益,用时间作为背包 ...

随机推荐

  1. C# 应用程序配置文件操作

    应用程序配置文件,对于asp.net是 web.config对于WINFORM程序是 App.Config(ExeName.exe.config). 配置文件,对于程序本身来说,就是基础和依据,其本质 ...

  2. Android studio disign 问题

    有些低配置的电脑使用android studio 写xml的时候,disign会一直处于rendering,有可能是xml使用的图片过大导致渲染不出来

  3. 【原创】有关Silverlight中“DataGrid中单元格动态绑定ComboBox单击时数据项莫名被清除 ”的解决方案及思路。

    今天上班遇到一个很古怪的问题,搞了半天愣是没找到原因.是这样的,在Datagrid中有绑定一个ComboBox列,其不包含在 model数据中,而是单独在LoadingRow事件中去 从数据库拿数据绑 ...

  4. WebApi 消息拦截

    最近公司要求对WebApi 实现服务端信息的监控(服务端信息拦截),由于本人之前没有做过这方便的相关项目所以在做的过程中也是困难重重,探索的过程也是非常痛苦的,好歹最终也算实现了这个功能.所以将这个分 ...

  5. LUA GC 简单测试

    function table.count(t) if type(t) ~= "table" then assert(false) return end for k, _ in pa ...

  6. 查询EBS请求日志的位置和名称

    select * from FND_CONCURRENT_PROGRAMS_VL fcp where fcp.USER_CONCURRENT_PROGRAM_NAME like '%CUX%XXXX% ...

  7. scrapy 代理

    说明: 本文参照了官网文档,以及stackoverflow的几个问题 概要: 在scrapy中使用代理,有两种使用方式 使用中间件 直接设置Request类的meta参数 方式一:使用中间件 要进行下 ...

  8. findstr()与strfind()的区别

    matlab中这两个字符串查找的函数findstr(), strfind()表明上看起来用法相似,效果也相似. 1. findstr(s1,s2)--在较长的字符串中查找较短的字符串出现的次数,并返回 ...

  9. 【转】其实你不知道MultiDex到底有多坑

    遭遇MultiDex 愉快地写着Android代码的总悟君往工程里引入了一个默默无闻的jar然后Run了一下, 经过漫长的等待AndroidStudio构建失败了. 于是带着疑惑查看错误信息. UNE ...

  10. 高层次综合(HLS)-简介

    本文是我近段时间的学习总结,主要参考了Xilinx的技术文档以及部分网上其他资料.文档主要包括ug998<Introduction to FPGA Design Using High-Level ...