题意:

n首歌和一首经典歌已知其长度,一首歌开始唱必须唱完,现在已知剩余时间,求最多能唱歌的个数并保证唱歌时间总长最大

分析:

留最后一个时间唱经典,然后对剩下的时间用背包求出最大个数,并求出总长最大的一个。

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
int n,t,dp[],a[];
int main()
{
int te,ca=;
scanf("%d",&te);
while(te--){
scanf("%d%d",&n,&t);
for(int i=;i<n;++i)
scanf("%d",&a[i]);
memset(dp,,sizeof(dp));
int maxv=;
for(int i=;i<n;++i)
for(int j=t-;j>=a[i];--j){
if(dp[j-a[i]]>||j==a[i])
dp[j]=max(dp[j],dp[j-a[i]]+);
maxv=max(maxv,dp[j]);
}
int tmp;
for(int i=t-;i>=;--i)
if(dp[i]==maxv){
tmp=i;
break;
}
if(maxv==)
printf("Case %d: %d %d\n",++ca,,);
else
printf("Case %d: %d %d\n",++ca,dp[tmp]+,tmp+);
}
return ;
}

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. UVa 12563 (01背包) Jin Ge Jin Qu hao

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

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

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

  8. UVA 12563 Jin Ge Jin Qu hao

    dp-背包 开始用普通dp写了一发发现没法确定最大时间... 后来看到大牛机智的写法,嗯...dp表示当前状态能否成立:然后从条件最好的状态开始遍历,直到这个状态成立然后退出遍历. 具体的看代码吧.. ...

  9. UVA - 12563 Jin Ge Jin Qu hao (01背包变形)

    此题应该注意两个点,首先背包容量应该缩减为t-1,因为最长的歌不超过三分钟,而劲歌金曲有678s,所以肯定要留出这个时间来.其次注意优先级,保证唱的歌曲数目最多,在此前提下尽可能的延长时间. 处理方法 ...

随机推荐

  1. 2014多校第一场J题 || HDU 4870 Rating(DP || 高斯消元)

    题目链接 题意 :小女孩注册了两个比赛的帐号,初始分值都为0,每做一次比赛如果排名在前两百名,rating涨50,否则降100,告诉你她每次比赛在前两百名的概率p,如果她每次做题都用两个账号中分数低的 ...

  2. hdu 1755 A Number Puzzle

    这题枚举k节省时间 ;}

  3. hdu 1352 I Conduit!

    计算几何,主要是排序问题,其他都很好做…… ;}

  4. 手把手VirtualBox虚拟机下安装rhel6.4 linux 64位系统详细文档

    下面演示安装的是在VirtualBox里安装rhel 6.4 linux 64位系统. 一.VirtualBOX 版本. 二.虚拟机的配置. 1.现在开始演示安装,一起从零开始.点击“新建”,创建新的 ...

  5. Java学习笔记(一) java介绍

    编程语言分为:编译型语言和解释型语言. 编译型语言需要经过特定编译器通过一次性编译,成为该特定平台硬件可执行的机器码,可脱离开发环境独立运行,运行效率较高,但是无法跨平台移植. 解释型语言需要经过特定 ...

  6. nginx的健康检查功能将挂掉的Tomcat舍弃

    1.Ngninx自带健康检查功能,能将挂掉的服务器舍弃,不在访问路径里 2.Nginx还有URL重写功能,能将接收到的请求,进行改写,再将新的URL分发到后端服务器上

  7. Linux下安装、配置、启动Apache

    http://www.cnblogs.com/zhuque/archive/2012/11/03/2763352.html#

  8. Failed to allocate memory: 8

    Failed to allocate memory: 8This application has requested the Runtime to terminate it in an unusual ...

  9. [HDOJ4027]Can you answer these queries?(线段树,特殊成段更新,成段查询)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4027 RT,该题要求每次更新是更新所有节点,分别求平方根,查询是求和.昨晚思前想后找有没有一个数学上的 ...

  10. Sublime Text3中文乱码及tabs中文方块的解决方案

    一.文本出现中文乱码问题 方案1 1.打开Sublime Text 3,按Ctrl+-打开控制行,复制粘贴以下python代码,然后回车运行. 2. 复制并粘贴如下代码: import urllib. ...