传送门

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. 洛谷 P3434 [POI2006]KRA-The Disks 贪心

    目录 题面 题目链接 题目描述 输入输出格式 输入格式 输出格式 输入输出样例 输出样例 输出样例 说明 思路 AC代码 题面 题目链接 P3434 [POI2006]KRA-The Disks 题目 ...

  2. 使用HashMap编写一程序实现存储某班级学生信息

    1. 使用HashMap编写一程序实现存储某班级学生信息,要求在屏幕上打印如下列表 学号   姓名   性别   年龄 001    张三   男      23 002    李四   男      ...

  3. linux命令格式及who、whoami、su和passwd命令

    linux命令格式及who.whoami.su和passwd命令 1. Linux命令的格式 Linux命令的语法格式: 命令 [选项] [参数] 命令格式中命令.选项.参数的具体含义: 命令:告诉L ...

  4. FastAdmin 自学教程 - 目录(持续更新)(2019-10-11)

    FastAdmin 自学教程 - 目录 本自学教程将不定期更新. 了解 FastAdmin FastAdmin 开发第 1 天:了解 FastAdmin 框架 FastAdmin 开发第 2 天:安装 ...

  5. iOS:你App的设置做对了吗?

    http://www.cocoachina.com/ios/20151217/14707.html iOS 8及以上版本最不为人知的一个特点是与应用设置的深层链接,用户可以根据APP的需要授权启用位置 ...

  6. Eclipse中提示 找不到类 javax.servlet.http.HttpServletResponse

    问题如题, 解决方案如下: 复制tomcat的安装路径下\lib\servlet-api.jar 到WEB-INF/lib下即可.

  7. HDU - 1875_畅通工程再续

    畅通工程再续 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Desc ...

  8. linux下安装composer以及使用composer安装laravel

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/nianzhi1202/article/details/72770099 一.安装composer之前 ...

  9. @bzoj - 2395@ [Balkan 2011]Timeismoney

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 有n个城市(编号从0..n-1),m条公路(双向的),从中选择n ...

  10. @loj - 2174@ 「FJOI2016」神秘数

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 一个可重复数字集合 S 的神秘数定义为最小的不能被 S 的子集的 ...