UVa 12563_Jin Ge Jin Qu hao
【题意】在KTV唱歌,假设每首歌最长180s,时间结束时如果还有歌正在唱,则将此歌唱完。为使唱歌时间最长,规定最后唱长达678s的《劲歌金曲》【介是个嘛?】
假设你正在唱KTV,在剩余的t秒时间里,在给定时长的n首歌里(不包括劲歌金曲),要尽可能的多唱。即 在唱的总曲目尽量多的前提下,尽量晚的离开KTV。求唱的总曲目及唱的时间总长度。
【分析】01背包先求最大的曲目数,再在此前提下求从最后遍历数组获取此前提下的最长时间,最后输出加上678
【代码】
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
using namespace std;
int v[100000];
int t[60];
int n,total;
const int mod=int(1e9)+7,INF=-1000000000,maxn=1e5+40;
void ZeroOnePack(int Case)
{
fill(v,v+100000,INF);
v[0]=0;
int temp=0;
for(int i=0;i<n;i++)
{
for(int j=total-1;j>=t[i];j--)
{
v[j]=max(v[j],v[j-t[i]]+1);
if(v[j]>temp) temp=v[j];
}
}
for(int i=total-1;i>=0;i--)
{
if(v[i]==temp)
{
cout<<"Case "<<Case+1<<": "<<temp+1<<" "<<i+678<<endl;
return;
}
}
}
int main (void)
{
int Case;
int Max=0;
cin>>Case;
for(int i=0;i<Case;i++)
{
cin>>n>>total;
memset(t,0,sizeof(t));
for(int j=0;j<n;j++) cin>>t[j];
ZeroOnePack(i);
}
}
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 ...
- UVA12563-Jin Ge Jin Qu hao(动态规划基础)
Problem UVA12563-Jin Ge Jin Qu hao Accept: 642 Submit: 7638Time Limit: 3000 mSec Problem Descriptio ...
- 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 ...
- 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
dp-背包 开始用普通dp写了一发发现没法确定最大时间... 后来看到大牛机智的写法,嗯...dp表示当前状态能否成立:然后从条件最好的状态开始遍历,直到这个状态成立然后退出遍历. 具体的看代码吧.. ...
随机推荐
- Android开源项目:GifView——Android显示GIF动画
下载:http://code.google.com/p/gifview/downloads/list 简介:android中现在没有直接显示gif的view,只能通过mediaplay来显示,且还常常 ...
- 在SQLServer 2005附加SQLServer 2008数据库异常处理
远程服务器软件系统不算新,数据库是SQL Server 2005.本地开发基本是用新的软件系统.数据库采用SQL Server 2008. 这样在用远程服务器SQL 2005选择附加SQL 2008的 ...
- OpenGL VAO, VBO 使用简介
参照代码样例: // This function takes in a vertex, color, index and type array // And does the initializati ...
- com口操作excel
_Application app; //Excel应用程序接口 Workbooks books; //工作薄集合 _Workbook book; //工作薄 Work ...
- 【JavaScript从入门到精通】第三课
第三课 初探JavaScript魅力-03 函数传参 上节课的时候我们已经讲了什么是函数,实际上,函数在功能上就类似于css的class一样,将一段代码包裹起来使用.为了让函数的功能更加的丰富和实用, ...
- JFinal项目eclipse出现the table mapping of model: com.gexin.model.scenic.Scenic not exists or the ActiveRecordPlugin not start.
JFinal项目eclipse出现the table mapping of model: com.gexin.model.scenic.Scenic not exists or the ActiveR ...
- “完美”解决微信小程序购物车抛物动画,在连续点击时出现计算错误问题,定时器停不下来。
最近做,微信点餐小程序,遇到添加商品时出现抛物动画,参考借鉴了这位大神的方法 https://www.cnblogs.com/greengage/p/7815842.html 但出现了一个问题,连续点 ...
- 【简●解】POJ 1845 【Sumdiv】
POJ 1845 [Sumdiv] [题目大意] 给定\(A\)和\(B\),求\(A^B\)的所有约数之和,对\(9901\)取模. (对于全部数据,\(0<= A <= B <= ...
- 珂朵莉树(Chtholly Tree)学习笔记
珂朵莉树(Chtholly Tree)学习笔记 珂朵莉树原理 其原理在于运用一颗树(set,treap,splay......)其中要求所有元素有序,并且支持基本的操作(删除,添加,查找......) ...
- Python之套接字
Python之套接字 客户端Client/服务端Server架构: 1.硬件C/S架构 2.软件C/S架构 OSI4层:4层里有五层,五层里又有7层. 四层---------五层--------七层 ...