继续战dp。不提。

题意分析

这题说白了就是一条01背包问题,因为对于给定的秒数你只要-1s(emmmmm)然后就能当01背包做了——那1s送给劲歌金曲(?)。比较好玩的是这里面dp状态的保存——因为要满足两个条件,因此我们的状态的定义也随之改变,使用自定义的结构体来保存。这个是我以前从来没接触过也没想到的。非常高级了,记下来。感谢想到的dalao!

代码

#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ZERO(x) memset((x),0,sizeof(x))
using namespace std;
int songs[55];
int n,maxt;
struct Node
{
int cnt,time;
Node(int _c=0,int _t=0):cnt(_c),time(_t) {}
bool operator < (const Node& rhs) const
{
if(cnt==rhs.cnt) return time<rhs.time;
else return cnt<rhs.cnt;
}
} dp[10005]; int main()
{
int t; cin>>t;
for(int kase=1;kase<=t;++kase)
{
memset(dp,0,sizeof(dp));
cin>>n>>maxt; maxt--;
for(int i=1;i<=n;++i)
cin>>songs[i];
for(int i=1;i<=n;++i)
for(int j=maxt;j>=songs[i];--j)
{
Node tmp(dp[j-songs[i]].cnt+1,dp[j-songs[i]].time+songs[i]);
if(dp[j]<tmp) dp[j]=tmp;
}
cout<<"Case "<<kase<<": "<<dp[maxt].cnt+1<<" "<<dp[maxt].time+678<<endl;
}
return 0;
}

【紫书】(UVa12563)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. 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 ...

  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——[DP递推]

    (If you smiled when you see the title, this problem is for you ^_^) For those who don’t know KTV, se ...

  5. uVa 12563 Jin Ge Jin Qu

    分析可知,虽然t<109,但是总曲目时间大于t,实际上t不会超过180*n+678.此问题涉及到两个目标信息,首先要求曲目数量最多,在此基础上要求所唱的时间尽量长.可以定义 状态dp[i][j] ...

  6. uva12563 Jin Ge Jin Qu hao(01背包)

    这是一道不错的题.首先通过分析,贪心法不可取,可以转化为01背包问题.但是这过程中还要注意,本题中的01背包问题要求背包必须装满!这就需要在普通的01背包问题上改动两处,一个是初始化的问题:把dp[0 ...

  7. 洛谷 UVA12563 Jin Ge Jin Qu hao 题解

    这道题其实是一道01背包的变形题,主要思路如下:在不把剩余时间用光的前提下(剩余时间>0),尽可能的多唱歌.于是我们可以用dp[i]表示的是到当前i秒时,最多可以唱多少歌. 状态转换方程:dp[ ...

  8. UVa 12563 (01背包) Jin Ge Jin Qu hao

    如此水的01背包,居然让我WA了七次. 开始理解错题意了,弄反了主次关系.总曲目最多是大前提,其次才是歌曲总时间最长. 题意: 在KTV房间里还剩t秒的时间,可以从n首喜爱的歌里面选出若干首(每首歌只 ...

  9. UVa 12563 Jin Ge Jin Qu hao【01背包】

    题意:给出t秒时间,n首歌分别的时间a[i],还给出一首长度为678的必须唱的劲歌金曲,问最多能够唱多少首歌(只要最后时间还剩余一秒,都可以将劲歌金曲唱完) 用dp[i]代表花费i时间时唱的歌的最大数 ...

随机推荐

  1. HDU 5025 Saving Tang Monk 【状态压缩BFS】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5025 Saving Tang Monk Time Limit: 2000/1000 MS (Java/O ...

  2. (转)理解YOLOv2训练过程中输出参数含义

    最近有人问起在YOLOv2训练过程中输出在终端的不同的参数分别代表什么含义,如何去理解这些参数?本篇文章中我将尝试着去回答这个有趣的问题. 刚好现在我正在训练一个YOLOv2模型,拿这个真实的例子来讨 ...

  3. JavaScript常用方法

    判断运行客户端 function isPhone() { var flag = false; var userAgentInfo = navigator.userAgent; var Agents = ...

  4. iOS 清除xcode缓存和生成文件

    方法1 按快捷键 shift+command+G 或者 Finder图标点击右键选 前往文件夹... 调出前往文件夹框 在里面输入如下 /Users/(自己电脑名字)/Library/Develope ...

  5. o'Reill的SVG精髓(第二版)学习笔记——第十章

    10.1 裁剪路径 创建SVG文档时,可以通过制定感兴趣区域的宽度和高度建立视口.这会变成默认的裁剪区域,任何绘制在该范围外部的部分都不会显示.你也可以使用<clipPath>元素来建立自 ...

  6. js使用hover事件做一个“个人中心”的浮动层

    原材料知识点:hover html: css:

  7. LeetCode11.盛最多水的容器 JavaScript

    给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0).找出其中的两条线, ...

  8. jmeter 填写URL链接后 不能有多余的空格。

  9. [USACO06NOV]玉米田Corn Fields(动态规划,状态压缩)

    题目描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ...

  10. 小a和uim之大逃离(dp)

    题目背景 小a和uim来到雨林中探险.突然一阵北风吹来,一片乌云从北部天边急涌过来,还伴着一道道闪电,一阵阵雷声.刹那间,狂风大作,乌云布满了天空,紧接着豆大的雨点从天空中打落下来,只见前方出现了一个 ...