【紫书】(UVa12563)Jin Ge Jin Qu hao
继续战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的更多相关文章
- 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 ...
- 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 ...
- 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——[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
分析可知,虽然t<109,但是总曲目时间大于t,实际上t不会超过180*n+678.此问题涉及到两个目标信息,首先要求曲目数量最多,在此基础上要求所唱的时间尽量长.可以定义 状态dp[i][j] ...
- uva12563 Jin Ge Jin Qu hao(01背包)
这是一道不错的题.首先通过分析,贪心法不可取,可以转化为01背包问题.但是这过程中还要注意,本题中的01背包问题要求背包必须装满!这就需要在普通的01背包问题上改动两处,一个是初始化的问题:把dp[0 ...
- 洛谷 UVA12563 Jin Ge Jin Qu hao 题解
这道题其实是一道01背包的变形题,主要思路如下:在不把剩余时间用光的前提下(剩余时间>0),尽可能的多唱歌.于是我们可以用dp[i]表示的是到当前i秒时,最多可以唱多少歌. 状态转换方程:dp[ ...
- 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时间时唱的歌的最大数 ...
随机推荐
- likelihood(似然) and likelihood function(似然函数)
知乎上关于似然的一个问题:https://www.zhihu.com/question/54082000 概率(密度)表达给定下样本随机向量的可能性,而似然表达了给定样本下参数(相对于另外的参数)为真 ...
- Joker Xue
大家好,我是LJ,来自于美丽的魏源故乡——隆回,从小被爸妈带到大,但是现在,我脱离了爸妈的管理,来到了远离家乡的长沙,大学生活当然美好,但是我们在做出每一个决定的同时,可能很少有他们的建议了,不过没有 ...
- 【字符串】跳来跳去的KMP匹配
原理: 不给予证明啦(懒得一批 但是代码中有给还算详细的注释 参考:https://www.cnblogs.com/yjiyjige/p/3263858.html 模板题: 洛谷P3375: http ...
- oracle序列中cache和nocache
首先我这篇博客的内容是我不知道oracle里的 cache 是什么,结果越查越多... "序列的cache通常为 20,但在需要依据序列值判断创建的先后顺序时必须是 NOCACHE" ...
- MvcApplication 中方法的那点事
最近比较闲,不知道干点啥,想找兼职没有合适的,不找工资又不够花,o(︶︿︶)o 唉! 说多了都是泪,入正题吧. 首先,新建一个MVC4.0项目,建好之后打开Global.asax文件,在MVCAppl ...
- $CRS_HOME/cdata下大量数字命名的文件,占用空间大
问题现象: <CRS_HOME>/cdata目录下存在大量数字命名的文件,导致文件系统爆满 $ls -alrth /opt/oracle/product/CRS/cdata/crs ...
- iOS之报错“Cannot create __weak reference in file using manual reference counting”解决办法
解决的办法:在Build Settings--------->Aplle LLVM8.0 - Language - Objectibe-C------------->Weak Refere ...
- DLL DEF文件编写方法 VC++ 调用、调试DLL的方法 显式(静态)调用、隐式(动态)调用
DLL 文件编写方法: 1.建立DLL工程 2.声明.定义要导出的函数 BOOL WINAPI InitDlg( HWND hTabctrl,TShareMem* pTshare,CRect* prc ...
- JAVA日期类图解
- 你应该要知道的JS中的this
前言 this 是 JavaScript 中不可不谈的一个知识点,它非常重要但又不容易理解.因为 JavaScript 中的 this 不同于其他语言.不同场景下的 this 指向不同(当函数被调用执 ...