传送门

debug了好一会,突然发现,输出错了,emmm.........

明天再写debug历程;

(PS:ipad debug是真的繁琐)

题意:

  

题解:

  尽管题干中给的 t 的范围很大,但是 t ≤ 50*180+678;

 int dp[maxn];///dp[i]:恰好唱i分钟时的最大曲目个数

AC代码:

 #include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
#define memF(a,b,n) for(int i=0;i <= n;a[i++]=b);
const int maxn=1e5+; int n,T;
int t[];
int dp[maxn]; void Solve()
{
memF(dp,-,T);
dp[]=;
for(int i=;i <= n;++i)
{
for(int j=T-;j >= t[i];--j)
{
if(dp[j-t[i]] != -)
dp[j]=max(dp[j],dp[j-t[i]]+);
}
}
int ans=*max_element(dp,dp+T-);
for(int i=T-;i >= ;--i)
if(dp[i] == ans)///查找曲目数==ans的最长时间
{
printf("%d %d\n",dp[i]+,i+);
return ;
}
}
int main()
{
int test;
scanf("%d",&test);
for(int kase=;kase <= test;++kase)
{
scanf("%d%d",&n,&T);
for(int i=;i <= n;++i)
scanf("%d",t+i); printf("Case %d: ",kase);
Solve();
}
return ;
}

坑:注意读题,曲目数的优先级高于时间;

UVA 12563 "Jin Ge Jin Qu hao" (背包)的更多相关文章

  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. 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 ...

  3. uVa 12563 Jin Ge Jin Qu

    分析可知,虽然t<109,但是总曲目时间大于t,实际上t不会超过180*n+678.此问题涉及到两个目标信息,首先要求曲目数量最多,在此基础上要求所唱的时间尽量长.可以定义 状态dp[i][j] ...

  4. 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 ...

  5. 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 ...

  6. 一道令人抓狂的零一背包变式 -- UVA 12563 Jin Ge Jin Qu hao

    题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...

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

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

  8. UVa 12563 Jin Ge Jin Qu hao【01背包】

    题意:给出t秒时间,n首歌分别的时间a[i],还给出一首长度为678的必须唱的劲歌金曲,问最多能够唱多少首歌(只要最后时间还剩余一秒,都可以将劲歌金曲唱完) 用dp[i]代表花费i时间时唱的歌的最大数 ...

  9. UVA - 12563 Jin Ge Jin Qu hao (01背包变形)

    此题应该注意两个点,首先背包容量应该缩减为t-1,因为最长的歌不超过三分钟,而劲歌金曲有678s,所以肯定要留出这个时间来.其次注意优先级,保证唱的歌曲数目最多,在此前提下尽可能的延长时间. 处理方法 ...

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

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

随机推荐

  1. Leetcode717.1-bit and 2-bit Characters1比特与2比特字符

    有两种特殊字符.第一种字符可以用一比特0来表示.第二种字符可以用两比特(10 或 11)来表示. 现给一个由若干比特组成的字符串.问最后一个字符是否必定为一个一比特字符.给定的字符串总是由0结束. 示 ...

  2. linux 添加文字、图形、线条、箭头的 截图

    1.deepin-screenshot 截图 软件包里搜索deepin-screenshot 支持添加文字.图形.线条.箭头的功能 2.字体发虚 Linux mint 开始菜单等字体不清晰 在软件管理 ...

  3. LintCode刷题笔记-- Count1 binary

    标签: 位运算 描述: Count how many 1 in binary representation of a 32-bit integer. 解题思路: 统计一个int型的数的二进制表现形式中 ...

  4. JavaCollection

    http://blog.csdn.net/itlwc/article/details/10148321 http://blog.sina.com.cn/s/blog_6d6f5d7d0100s9nu. ...

  5. JS放在body与head中的不同

    放在body和head其实差不多的,只不过是文档解析的时间不同.浏览器解析html是从上到下的.如果把javascript放在head里的话,则先被解析,但这时候body还没有解析,所以$(#btn) ...

  6. day39-Spring 13-Spring的JDBC模板:默认连接池的配置

    Spring内置的连接池DriverManagerDataSource的源码. /* * Copyright 2002-2008 the original author or authors. * * ...

  7. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第八章:光照

    原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第八章:光照 代码工程地址: https://github.com/j ...

  8. apache服务器配置防盗链(centos7)

    <Directory /data/wwwroot/xwl.com> SetEnvIfNoCase Referer "^$" local_ref SetEnvIfNoCa ...

  9. H5页面在iOS网页中的数字被识别为电话号码,字体颜色变黑色,且颜色不可改变

    解决办法:在html中添加代码: <meta name="format-detection" content="telephone=no" />

  10. typeid, const_cast<Type>的使用

    #include <bits/stdc++.h> using namespace std; class A { public : void Show() { cout << & ...