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

  处理方法:开创结构体,在歌曲数目相等的时候,选取最长时间。

  注意:注意t的大小,t完全没有必要计算那么大的数据。 代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 10010
int w[];
struct DP
{
int song,tim;
}dp[N];
int main()
{
// freopen("1.in.cpp","r",stdin);
int T,n,t,ca=,sum;
cin>>T;
while(T--)
{
cin>>n>>t;
sum = ;
for(int i = ; i <= n; i++) {
cin>>w[i];
sum += w[i];
}
if(t > sum){
if(t < sum + ) t = sum + ;
printf("Case %d: %d %d\n",++ca,n+,t);
continue;
}
t--;
for(int i = ;i < N;i++) dp[i].song = dp[i].tim = ;
for(int i = ; i <= n; i++)
{
for(int j = t; j >= w[i]; j--)
{
if(dp[j-w[i]].song+ > dp[j].song)
{
dp[j].song = dp[j-w[i]].song + ;
dp[j].tim = dp[j-w[i]].tim + w[i];
}
if(dp[j-w[i]].song+ == dp[j].song)
{
dp[j].tim = max(dp[j].tim,dp[j-w[i]].tim + w[i]);
}
}
}
printf("Case %d: %d %d\n",++ca,dp[t].song+,dp[t].tim+);
}
return ;
}

UVA - 12563 Jin Ge Jin Qu hao (01背包变形)的更多相关文章

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

  2. UVA12563Jin Ge Jin Qu hao(01背包)

    紫书P274 题意:输入N首歌曲和最后剩余的时间t,问在保证能唱的歌曲数目最多的情况下,时间最长:最后必唱<劲歌金曲> 所以就在最后一秒唱劲歌金曲就ok了,背包容量是t-1,来装前面的歌曲 ...

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

  4. uVa 12563 Jin Ge Jin Qu

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

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

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

  7. FZU 2214 Knapsack problem 01背包变形

    题目链接:Knapsack problem 大意:给出T组测试数据,每组给出n个物品和最大容量w.然后依次给出n个物品的价值和体积. 问,最多能盛的物品价值和是多少? 思路:01背包变形,因为w太大, ...

  8. codeforce Gym 101102A Coins (01背包变形)

    01背包变形,注意dp过程的时候就需要取膜,否则会出错. 代码如下: #include<iostream> #include<cstdio> #include<cstri ...

  9. HDU 2639 Bone Collector II(01背包变形【第K大最优解】)

    Bone Collector II Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  10. 【01背包变形】Robberies HDU 2955

    http://acm.hdu.edu.cn/showproblem.php?pid=2955 [题意] 有一个强盗要去几个银行偷盗,他既想多抢点钱,又想尽量不被抓到.已知各个银行 的金钱数和被抓的概率 ...

随机推荐

  1. 【Loadrunner】初学Loadrunner——录制脚本、回放、以及优化

    一.脚本录制(录制) 打开Loadrunner > 选择创建/编辑脚本 > NewScript > 选择协议(单协议.多协议) > Strart Recording >选 ...

  2. spring容器启动的加载过程(二)

    第六步: public abstract class AbstractApplicationContext extends DefaultResourceLoader implements Confi ...

  3. 小箭头的写法,z-index在ie7显示混乱问题

    一.jQuery 发布 1.9 正式版,最后支持 IE 6/7/8,2.0以上的版本都不支持这三个浏览器了. 二.小箭头的写法与旋转切换(一直以为这样的只以切图片,原来未必哦.) <style& ...

  4. Learning BSD.sys/queue.h

    This file includes 4 data-structures.. Insteresting because they are written in 1994.. to make it ea ...

  5. # Linux Whois3获取 运营商信息

    Linux Whois3获取 运营商信息 APNIC是管理亚太地区IP地址分配的机构,它有着丰富准确的IP地址分配库,同时这些信息也是对外公开的,并提供了一个查询工具,下面就让我们看看如何在Linux ...

  6. 用Visual Studio 2015 编写第一个UMDF驱动遇到的问题!!

    前提:Visual Studio 2015已经成功安装了驱动环境,WDK都已经完全正常安装了,在Visual Studio 2015的菜单可以看到"Driver"菜单项了.这说明已 ...

  7. C语言介绍

    以下东东转自百度百科 C语言是一种计算机程序设计语言,它既具有高级语言的特点,又具有汇编语言的特点.它由美国贝尔实验室的Dennis M. Ritchie于1972年推出,1978年后,C语言已先后被 ...

  8. APUE读书笔记:进程控制

    重点函数:fork,exit,_exit 一.fork 函数原型: #include <unistd.> pid_t fork(void) 函数说明:fork函数将创建一个子进程,该函数调 ...

  9. .net项目svn项目管理文件清单

    You can add the following files to Visual Studio source control: Solution files (*.sln). Project fil ...

  10. Replication--进程无法在“xxxx”上执行“sp_replcmds”

    错误消息:进程无法在“xxxx”上执行“sp_replcmds”. (源: MSSQL_REPL,错误号: MSSQL_REPL20011)获取帮助: http://help/MSSQL_REPL20 ...