【紫书】(UVa12563)Jin Ge Jin Qu hao
2024-09-04 16:07:09
继续战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;
}
最新文章
- string常用函数
- 《UML大战需求分析》阅读笔记02
- 【转】修改 shellstyle.dll 权限
- Android SDK Android NDK 官方下载地址
- Cocos2d-x加速度计实例:运动的小球
- [Android]通过setImageURI设置网络上面的图片
- JAVA模板方法模式
- pyhton中的Queue(队列)
- 安装 docker-compose
- [java面试]逻辑推理6 10 18 32 下一个数?编程实现输入任意一个N位置,该数是多少?java实现
- switch窗口句柄
- 微信小程序发送短信验证码完整实例
- 如何给框架添加API接口日志
- Docker系列(一)CentOS 6.5 离线安装、不升级内核
- [1]字符串按中文符占3位进行指定长度剪切[2]Double类型截取指定长度(指定长度=整数位+小数位)
- 自己对Java的一些认识
- 阿里云服务器用smtp发送邮件返失败
- python通过sftp远程传输文件
- python3-----多进程、多线程、多协程
- Web.config中 mode=";RemoteOnly"; 跟mode=";On"; 区别
热门文章
- VOJ1049 送给圣诞夜的礼品 【矩阵经典4】
- Windows后门小计
- caffe实现focal loss层的一些理解和对实现一个layer层易犯错的地方的总结
- doppia代码支持
- Linq 集合比较
- 11java基础继承
- 剑指offer——27. 二叉搜索树与双向链表(Java版)
- js中的AJAX
- Javafxml
- 一个logstash引发的连环案,关于logstash提示:Reached open files limit: 4095, set by the &#39;max_open_files&#39; option or default, files yet to open: 375248