继续战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. POJ 1191 棋盘分割 【DFS记忆化搜索经典】

    题目传送门:http://poj.org/problem?id=1191 棋盘分割 Time Limit: 1000MS   Memory Limit: 10000K Total Submission ...

  2. Android学习笔记_65_登录功能本身没有任何特别

    对于登录功能本身没有任何特别,使用httpclient向服务器post用户名密码即可.但是为了保持登录的状态(在各个Activity之间切换时要让网站知道用户一直是处于登录的状态)就需要进行cooki ...

  3. SpringCloud微服务实战:一、Eureka注册中心服务端

    1.项目启动类application.java类名上增加@EnableEurekaServer注解,声明是注册中心 1 import org.springframework.boot.SpringAp ...

  4. vue+nodejs+express+mysql 建立一个在线网盘程序

    vue+nodejs+express+mysql 建立一个在线网盘程序 目录 vue+nodejs+express+mysql 建立一个在线网盘程序 第一章 开发环境准备 1.1 开发所用工具简介 1 ...

  5. ES6 async await

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. 【学时总结】◆学时·IX◆ 整体二分

    ◆学时·IX◆ 整体二分 至于我怎么了解到这个算法的……只是因为发现一道题,明显的二分查找,但是时间会爆炸,被逼无奈搜题解……然后就发现了一些东西QwQ ◇ 算法概述 整体二分大概是把BFS与二分查找 ...

  7. mysql like 变量

    Mysql: select * from 表名 where 字段 like concat('%',变量,'%');  

  8. Recycler实现瀑布流

    (开发环境Android studio) 首先,在开发环境中添加引用(在外层的build.gradle文件下的dependencies里面添加如下引用) implementation 'com.and ...

  9. 汇编:模拟C语言实现break与continue

    ;=============================== ;循环程序设计 ;模拟C语言实现break 与continue DATAS SEGMENT i dw sum dw DATAS end ...

  10. 阿里云SSL证书到期(续期)图文教程

    今天公司项目突然报错 后来查询是SSL证书过期了.友情提示: 证书产品仅支持新签发.不支持续费.证书到期前需在阿里云SSL证书控制台重新购买和申请证书. 登录阿里云控制台,点击产品与服务,在搜索框搜索 ...