UVA 12563 Jin Ge Jin Qu hao
dp-背包
开始用普通dp写了一发发现没法确定最大时间。。。
后来看到大牛机智的写法,嗯。。。dp表示当前状态能否成立;然后从条件最好的状态开始遍历,直到这个状态成立然后退出遍历。
具体的看代码吧。。。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std; int dp[][];
int d[]; int main (){
int T,kase=;
cin>>T;
while (T--){
int n,t;
cin>>n>>t;
for (int i=;i<n;i++){
cin>>d[i];
}
sort (d,d+n);
memset (dp,,sizeof dp);
dp[][]=;
for (int k=;k<n;k++){
for (int j=t;j>=d[k];j--){
for (int i=k+;i>;i--){
if (dp[i-][j-d[k]])
dp[i][j]=;
}
}
}
int ans=;
int time;
int flag=;
for (int i=n;i>=;i--){
for (int j=t-;j>=;j--){//cout<<j<<" ";
if (dp[i][j]){
ans=i;
time=j;
flag=;
break ;
}
}
if (flag)
break ;
}
cout<<"Case "<<++kase<<": "<<ans+<<" "<<time+<<endl;
}
return ;
}
UVA 12563 Jin Ge Jin Qu hao的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- uVa 12563 Jin Ge Jin Qu
分析可知,虽然t<109,但是总曲目时间大于t,实际上t不会超过180*n+678.此问题涉及到两个目标信息,首先要求曲目数量最多,在此基础上要求所唱的时间尽量长.可以定义 状态dp[i][j] ...
- 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 ...
- 一道令人抓狂的零一背包变式 -- UVA 12563 Jin Ge Jin Qu hao
题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...
- UVa 12563 (01背包) Jin Ge Jin Qu hao
如此水的01背包,居然让我WA了七次. 开始理解错题意了,弄反了主次关系.总曲目最多是大前提,其次才是歌曲总时间最长. 题意: 在KTV房间里还剩t秒的时间,可以从n首喜爱的歌里面选出若干首(每首歌只 ...
- UVa 12563 Jin Ge Jin Qu hao【01背包】
题意:给出t秒时间,n首歌分别的时间a[i],还给出一首长度为678的必须唱的劲歌金曲,问最多能够唱多少首歌(只要最后时间还剩余一秒,都可以将劲歌金曲唱完) 用dp[i]代表花费i时间时唱的歌的最大数 ...
- UVA - 12563 Jin Ge Jin Qu hao (01背包变形)
此题应该注意两个点,首先背包容量应该缩减为t-1,因为最长的歌不超过三分钟,而劲歌金曲有678s,所以肯定要留出这个时间来.其次注意优先级,保证唱的歌曲数目最多,在此前提下尽可能的延长时间. 处理方法 ...
随机推荐
- Javascript经典实例 - 正则表达式
1] 正则常用字符 正则表达式常用的特殊字符 字符 匹配 示例 ^ 匹配输入的开始 /^This/匹配 “This is ...” $ 匹配输入的结束 /end$/匹配“This is the end ...
- 查文件大小列表 MySQL问题
du -sh /* | sort -nr 打开网站发现Too many connections The server quit without updating PID file (/usr/loca ...
- 负载均衡集群之LVS配置命令
ipvs/ipvsadm 添加集群服务--> ipvsadm -A|E -t|u|f VIP[:Port] -s scheduler [-p timeout] [-O] [-M netmask] ...
- mysql 执行reset master 风险
reset master 会把mysql实例上的所以二进制日志删除,并且日志序列从1开始:这样会引起两个问题. 001.问题一 slave 由于找不到下一个要执行的事件所以会报错.进一步master- ...
- shell脚本语法基础汇总
shell脚本语法基础汇总 将命令的输出读入一个变量中,可以将它放入双引号中,即可保留空格和换行符(\n) out=$(cat text.txt) 输出1 2 3 out="$(cat te ...
- House Robber II 解答
Question After robbing those houses on that street, the thief has found himself a new place for his ...
- Linux系统下定时上传文件至FTP服务器脚本
环境:Red Hat Enterprise Linux Server release 6.4 需求:需要将Oracle数据库的定时备份上传至FTP服务器 1.干货,用户名:oracle,数据库名称:X ...
- 让你的javascript函数拥有记忆功能,降低全局变量的使用
考虑例如以下场景:假如我们须要在界面上画一个圆,初始的时候界面是空白的.当鼠标移动的时候,圆须要尾随鼠标移动.鼠标的当前位置就是圆心.我们的实现方案是:假设界面上还没有画圆,那么就新创建一个:假设已经 ...
- hdu 4611
2013hdu多校联赛二的第一题,当时队友说两个盒子个数的最小公倍数是周期, 如果两个数的最小公倍数比较大的时候(最大是9999900000),如果遍历求的话肯定会超时 当时想找各种规律,都没找到,最 ...
- Oracle Enterprise linux 7 安装Oracle11gR2
一.修改主机名和IP地址: [root@localhost Desktop]# cat /etc/hosts127.0.0.1 localhost.localdomain localhost 192. ...