每首只能唱一次,而且中间不能不唱歌,所以先把状态赋值为-1,以区别合法状态和非法状态,在唱歌曲目最多的条件下,离开时间应该尽量晚。

状态定义f[i][j]考虑前i首歌唱歌时间为j的最大唱歌曲目

#include<bits/stdc++.h>
using namespace std; const int maxn = ; const int maxt = *maxn+; int f[maxt]; const int JinGe = ;
int main()
{
//freopen("in.txt","r",stdin);
int T; scanf("%d",&T);
int kas = ;
while(T--){
int n,t; scanf("%d%d",&n,&t);
int k = ;
memset(f,-,sizeof(int)*t);
f[] = ;
for(int i = ; i < n; i++){
int V ; scanf("%d",&V);
for(int j = t-; j >= V; j--){
if(~f[j-V] && ( f[j] < f[j-V]+ ) ){
f[j] = f[j-V]+;
if(f[j] > f[k] || ( f[j] == f[k] && k < j ) ){
k = j;
}
}
}
} printf("Case %d: %d %d\n",++kas,f[k]+,k+JinGe); }
return ;
}

UVA 12563 Jin Ge jin Qu [h] ao 劲歌金曲 (01背包)的更多相关文章

  1. UVA 12563 劲歌金曲(01背包)

    劲歌金曲 [题目链接]劲歌金曲 [题目类型]01背包 &题解: 题意:求在给定时间内,最多能唱多少歌曲,在最多歌曲的情况下,使唱的时间最长. 该题类似于01背包问题,可用01背包问题的解题思路 ...

  2. uVa 12563 Jin Ge Jin Qu

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

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

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

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

  7. 一道令人抓狂的零一背包变式 -- UVA 12563 Jin Ge Jin Qu hao

    题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...

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

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

  9. 【UVa 12563】Jin Ge Jin Qu hao

    [Link]: [Description] KTV给你T秒的唱歌时间; 你有n首一定要唱的歌; 然后有一首很变态的歌有678s,你想在T秒结束之前唱一下这首歌; 因为这样的话,你能尽量晚地走出KTV( ...

随机推荐

  1. 1.5 sqoop安装及基本使用

    一.安装sqoop 1.解压 ##解压 [root@hadoop-senior cdh]# tar zxf sqoop-1.4.5-cdh5.3.6.tar.gz -C /opt/cdh-5.3.6/ ...

  2. 20个Flutter实例视频教程-01节底部导航栏和切换效果的制作-1

    视频地址: https://www.bilibili.com/video/av39709290?zw 博客地址: https://jspang.com/post/flutterDemo.html#to ...

  3. JSONObject put List<Double> 后转化为String问题的解决办法

    //原代码 JSONObject powerCurveJsonObj = new JSONObject(); powerCurveJsonObj.put("test",[0.5, ...

  4. Black Box--[优先队列 、最大堆最小堆的应用]

    Description Our Black Box represents a primitive database. It can save an integer array and has a sp ...

  5. 洛谷1601 A+B Problem(高精) 解题报告

    洛谷1601 A+B Problem(高精) 本题地址:http://www.luogu.org/problem/show?pid=1601 题目背景 无 题目描述 高精度加法,x相当于a+b pro ...

  6. 51nod - 1420 - 数袋鼠好有趣 - 贪心 - 二分

    https://www.51nod.com/Challenge/Problem.html#!#problemId=1420 一开始乱搞了一发,每个袋鼠二分找最小的能放它的,然后二分的范围从下一个开始保 ...

  7. Bundle Adjustment光束平差法概述

    http://blog.csdn.net/abcjennifer/article/details/7588865 http://blog.csdn.net/ximenchuixuezijin/arti ...

  8. Validation(3)--全局参数异常校验捕获及返回XML解决

    @RestControllerAdvice原创直接上代码,后面再说怎么用1.这个是一个Form,用来接收参数的,一个简单的NotEmpty注解校验,merchantName这个参数是必传的: pack ...

  9. django (三) admin后台系统

    admin后台系统 1. 安装MySQL 1,安装mysql: sudo apt install mysql-server   (安装过程中输入密码并牢记)   2,安装后进入mysql: mysql ...

  10. Codeforces Round #532(Div. 2) B.Build a Contest

    链接:https://codeforces.com/contest/1100/problem/B 题意: 给n,m. 给m个数,每个数代表一个等级,没给一个将其添加到题目池中,当题目池中有难度(1-n ...