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表示当前状态能否成立:然后从条件最好的状态开始遍历,直到这个状态成立然后退出遍历. 具体的看代码吧.. ...
随机推荐
- Repeater 的使用
<HeaderTemplate></HeaderTemplate> 头模板——在加载开始执行一遍 <FooterTemplate></FooterTempl ...
- 如何成为一名优秀的 iOS 开发工程师
如果你是一位专业的iOS开发工程师,你应该为自己感到自豪.因为你能在强大的iOS系统下,一展身手实现自己和他人的想法,这是一件令人无比激动的事情. 作为一名iOS开发工程师,你一定想成为行业的佼佼者. ...
- String的用法——转换功能
package cn.itcast_05; /* String类的转换功能: byte[] getByte():把字符串转换成字节数组 复习: public String(byte[] bytes): ...
- CSS定位内容
div.h1 或 p 元素常常被称为块级元素.这意味着这些元素显示为 一块内容,即“块框”.与之相反,span 和 strong 等元素称为“行 内元素”,这是因为它们的内容显示在行中,即 ...
- Node.js——网站访问一般流程
- 洛谷 P3388 【模板】割点
题目背景 割点 题目描述 给出一个n个点,m条边的无向图,求图的割点. 输入输出格式 输入格式: 第一行输入n,m 下面m行每行输入x,y表示x到y有一条边 输出格式: 第一行输出割点个数 第二行按照 ...
- Ghost Win10系统X64位和32位10041装机版下载
更多系统下载尽在系统妈:http://www.xitongma.com 特别说明: 1.C:盘分区须至少15GB(安装过程有大量的解压临时文件),安装完成后C:盘占用10GB左右! 2.安装之后如有硬 ...
- 安卓 Android 简单数据库(增删改查)
<Button android:id="@+id/delete_btn" android:layout_width="wrap_content" andr ...
- fedora27安装ssh
Fedora安装sshd 先确认是否已安装ssh服务: [root@localhost ~]# rpm -qa | grep openssh-server openssh-server-5.3p1-1 ...
- Flutter走过的坑(持续更新)
1 Target of URI doesn't exist 'package:flutter/material.dart' 官方下载的flutter中有一个example文件夹,里面有很多flutte ...