紫书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. smarty中foreach的用法举例

  2. 课题:如何培养自己的SEO资源

    课题:如何培养自己的SEO资源 问:做SEO最重要的是什么?[针对性的流量]答:看获取一样东西的门槛.稀缺性,人人可得价值不大外链 内容 流量[正确]针对性的自然流量是用户自愿带来的,价值高,能形成购 ...

  3. 了解了这些才能开始发挥jQuery的威力(转)

    链接:http://www.cnblogs.com/dolphinX/archive/2013/10/08/3347677.html 由于当前jQuery如此的如雷贯耳,相信不用介绍什么是jQuery ...

  4. 加密算法使用(二):使用MD5加密字符串(另:byte数组转16进制自动补零方法写法)

    public static void main(String args[]) throws NoSuchAlgorithmException { String s = new String(" ...

  5. opencv2学习:计算协方差矩阵

    图像的高级处理中,协方差矩阵计算是必不可少的,但opencv关于这方面的资料却相当少. 首先,利用matlab计算一下,便于比较: >> data=[1,2,3;10,20,30] dat ...

  6. swift语言的学习笔记

    swift参考了OC,Rust,Haskell,Ruby,Python,C#等语言的特性.首先,学习这门语言是速学的,我不想浪费太多时间在笔记这门语言和其他语言的哪里不同,特性你自己亲自实践就知道了. ...

  7. HoloLens开发手记 - Unity之Spatial Sounds 空间声音

    本文主要讲述如何在项目中使用空间声音特性.我们主要讲述必须的插件组件和Unity声音组件和属性的设置来确保空间声音的实现. Enabling Spatial Sound in Unity 在Unity ...

  8. STM32的USB速度,终于确定了传输极限,为以后的产品设计提供了数据。

    是自定协议,用到一个bulk in ep1, 一个bulk out ep2 端点  用虚拟串口的优点显而易见,上位机的编写非常方便,就按照常规的串口功能编写就可以了,而速度确还是usb的速度  USB ...

  9. 解决BeanNotOfRequiredTypeException: Bean named 'XXX' must be of type XXX, but was actually of type XXX问题

    Java新手,困扰了一下午. 发布时总是报这样一个错误. org.springframework.beans.factory.BeanCreationException: Error creating ...

  10. http技术交流提纲

    http技术交流提纲地址:http://lazio10000.github.io/tech/http/#/bored