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表示当前状态能否成立:然后从条件最好的状态开始遍历,直到这个状态成立然后退出遍历. 具体的看代码吧.. ...
随机推荐
- 解决okHttp使用https抛出stream was reset: PROTOCOL_ERROR的问题
昨天在做Android接口调用的时候,api接口是https的,用okhttp抛出: okhttp3.internal.http2.StreamResetException: stream was r ...
- swiper4实现的拥有header和footer的全屏滚动demo/swiper fullpage footer
用swiper4实现的拥有header和footer的全屏滚动demo, <!DOCTYPE html> <html lang="en"> <head ...
- 12 DOM操作应用
1.创建子元素oLi=document.creatElement('li') 2.将元素附给父级元素oUl.appendChild(oLi) 3.将元素插入到父级元素里的第一位子元素之前oUl.ins ...
- vue-element:文件上传七牛之key和异步的问题
效果图: html 代码: <el-form-item label="Excel文件" :label-width="formLabelWidth" pro ...
- oracle 代码块
oracle 的代码块模板 declare --声明变量 begin --执行业务逻辑 exception --异常处理 end; --结束 注意:代码块每个sql语句结束都要加冒号 eg: --pl ...
- iOS Programming Dynamic Type 1
iOS Programming Dynamic Type 1 Dynamic Type is a technology introduced in iOS 7 that helps realize ...
- 动态生成表格呈现还是将表格直接绑定gridview等控件呈现的开发方式选择依据
动态生成表格呈现还是将表格直接绑定gridview等控件呈现的开发方式选择依据:由存储过程决定,如果编写的存储过程可以生成需要呈现的表格则直接绑定,否则要动态生成表格
- 数组(Arry)几个常用方法的详解
join() 方法用于把数组中的所有元素放入一个字符串.元素是通过指定的分隔符进行分隔的. arrayObject.join(separator)separator 可选.指定要使用的分隔符.如果省略 ...
- 【C++】朝花夕拾——STL vector
STL之vector篇 N久之前是拿C的数组实现过vector中的一些简单功能,什么深拷贝.增删查找之类的,以为vector的实现也就是这样了,现在想想真是...too young too naive ...
- codeforces_B. Forgery
http://codeforces.com/contest/1059/problem/B 题意: For simplicity, the signature is represented as an ...