【题意】在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的更多相关文章

  1. 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 ...

  2. UVA12563-Jin Ge Jin Qu hao(动态规划基础)

    Problem UVA12563-Jin Ge Jin Qu hao Accept: 642  Submit: 7638Time Limit: 3000 mSec Problem Descriptio ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  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

    dp-背包 开始用普通dp写了一发发现没法确定最大时间... 后来看到大牛机智的写法,嗯...dp表示当前状态能否成立:然后从条件最好的状态开始遍历,直到这个状态成立然后退出遍历. 具体的看代码吧.. ...

随机推荐

  1. ASP.NET URLRewriter重写

    URLRewriter重写是微软官方出的第三方重写插件 下载地址:http://download.csdn.net/detail/ysn1314/5421587 下载后在项目中添加引用,然后再配置文件 ...

  2. LN : leetcode 712 Minimum ASCII Delete Sum for Two Strings

    lc 712 Minimum ASCII Delete Sum for Two Strings 712 Minimum ASCII Delete Sum for Two Strings Given t ...

  3. [BZOJ1005][HNOI2008]明明的烦恼 数学+prufer序列+高精度

    #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int N; ...

  4. js 将XML字符串解析成XML文档 --- attribute construct error--- 空白字符与空格问题

    最近在做xml在线编辑器,遇到一个字符串解析成xml文档的问题,记录一下. 原始xml内容读取自xml文档 <label class="test" id="labe ...

  5. sublime text3安装Package Control

    转自:https://www.cnblogs.com/lq147760524/p/8202521.html 一.下载Sublime3 https://www.sublimetext.com/3 二.安 ...

  6. R in action读书笔记(8)-第八章:回归(上)

    8.1回归的多面性 8.2 OLS回归 OLS回归拟合模型形式: 为了能够恰当地解释oLs模型的系数,数据必须满足以下统计假设. 口正态性对于固定的自变量值,因变量值成正态分布. 口独立性Yi值之间相 ...

  7. iOS-UI控件之UIImageView

    contentMode属性 带有scale单词的:图片有可能会拉伸 UIViewContentModeScaleToFill 将图片拉伸至填充整个imageView 图片显示的尺寸跟imageView ...

  8. win7电脑桌面壁纸曝光过高影响图标怎么办?亲测实用解决方法

    现在用win7系统的人应该还是挺多的吧,虽然说windows家族已经升级到现在的win11了,相信大多数人家用的电脑系统还是win7吧,今天要讲的是一个壁纸曝光度过高的解决办法,虽然还不清楚为什么,但 ...

  9. iOS重签

    由于渠道推广需要,可能需要多个包做备份推广,区别是icon.游戏名称.登录logo.bundleid.签名证书.支付Consumables不同,其他游戏包体完全相同. 反复修改多次文件提交Jenkin ...

  10. 扩展IHttpHandler

    前面提到当请求进入到IIS,IIS转发给ISAPI后会根据文件的后缀名来决定将请求转发给对应的处理程序进行处理,当然一大部分的处理都是交给了AspNet_ISAPI 了.但是,AspNet_ISAPI ...