基本的01背包,更新的时候保持背包里每一个元素的num最大然后time尽量长

CSDN也支持makedown了试一下


12563 Jin Ge Jin Qu hao
(If you smiled when you see the title, this problem is for you ^_^)
For those who don’t know KTV, see: http://en.wikipedia.org/wiki/Karaoke_box
There is one very popular song called Jin Ge Jin Qu(劲歌金曲). It is a mix of 37 songs, and is
extremely long (11 minutes and 18 seconds) — I know that there are Jin Ge Jin Qu II and III, and
some other unofficial versions. But in this problem please forget about them.
Why is it popular? Suppose you have only 15 seconds left (until your time is up), then you should
select another song as soon as possible, because the KTV will not crudely stop a song before it ends
(people will get frustrated if it does so!). If you select a 2-minute song, you actually get 105 extra
seconds! ….and if you select Jin Ge Jin Qu, you’ll get 663 extra seconds!!!
Now that you still have some time, but you’d like to make a plan now. You should stick to the
following rules:
• Don’t sing a song more than once (including Jin Ge Jin Qu).
• For each song of length t, either sing it for exactly t seconds, or don’t sing it at all.
• When a song is finished, always immediately start a new song.
Your goal is simple: sing as many songs as possible, and leave KTV as late as possible (since we
have rule 3, this also maximizes the total lengths of all songs we sing) when there are ties.
Input
The first line contains the number of test cases T (T ≤ 100). Each test case begins with two positive
integers n, t (1 ≤ n ≤ 50, 1 ≤ t ≤ 109
), the number of candidate songs (BESIDES Jin Ge Jin Qu)
and the time left (in seconds). The next line contains n positive integers, the lengths of each song, in
seconds. Each length will be less than 3 minutes — I know that most songs are longer than 3 minutes.
But don’t forget that we could manually “cut” the song after we feel satisfied, before the song ends. So
here “length” actually means “length of the part that we want to sing”.
It is guaranteed that the sum of lengths of all songs (including Jin Ge Jin Qu) will be strictly larger
than t.
Output
For each test case, print the maximum number of songs (including Jin Ge Jin Qu), and the total lengths
of songs that you’ll sing.
Explanation:
In the first example, the best we can do is to sing the third song (80 seconds), then Jin Ge Jin Qu
for another 678 seconds.
In the second example, we sing the first two (30+69=99 seconds). Then we still have one second
left, so we can sing Jin Ge Jin Qu for extra 678 seconds. However, if we sing the first and third song
instead (30+70=100 seconds), the time is already up (since we only have 100 seconds in total), so we
can’t sing Jin Ge Jin Qu anymore!Universidad de Valladolid OJ: 12563 – Jin Ge Jin Qu hao 2/2
Sample Input
2
3 100
60 70 80
3 100
30 69 70
Sample Output
Case 1: 2 758
Case 2: 3 777

/* ***********************************************
Author        :CKboss
Created Time  :2015年02月08日 星期日 10时45分24秒
File Name     :UVA12563_2.cpp
************************************************ */#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>using namespace std;int n,t,ti[111];struct ST
{int num,time;
};ST dp[110][11000];bool check(int a,int b,int time)
{int c=a-1 , d=b-time;if((dp[c][d].num+1>dp[a][b].num)||((dp[c][d].num+1==dp[a][b].num)&&(dp[c][d].time+time>=dp[a][b].time))) return true;else return false;
}int main()
{//freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);int T_T,cas=1;scanf("%d",&T_T);while(T_T--){scanf("%d%d",&n,&t);int sumtime=0;for(int i=1;i<=n;i++) {scanf("%d",ti+i);sumtime+=ti[i];}if(sumtime<t){printf("Case %d: %d %d\n",cas++,n+1,sumtime+678);continue;}memset(dp,0,sizeof(dp));for(int i=1;i<=n;i++){for(int j=0;j<t;j++){dp[i][j]=dp[i-1][j];if(j-ti[i]>=0){if(check(i,j,ti[i])){dp[i][j].num=dp[i-1][j-ti[i]].num+1;dp[i][j].time=dp[i-1][j-ti[i]].time+ti[i];}}}}ST ok=dp[n][0];for(int i=1;i<t;i++){ST e = dp[n][i];if((e.num>ok.num)||(e.num==ok.num&&e.time>ok.time))ok=e;}printf("Case %d: %d %d\n",cas++,ok.num+1,ok.time+678);}return 0;
}

UVA 12563 Jin Ge Jin Qu hao 01背包变形相关推荐

  1. UVa 12563 Jin Ge Jin Qu hao(01背包)

    题意  你在KTV还剩t秒钟的时间  你需要在n首歌中选择尽量多的歌使得歌的数量最多的前提下剩下的时间最小 至少要留一秒给劲歌金曲  所以是一个容量为t-1的01背包   d[i][j]表示恰用j秒时 ...

  2. Jin Ge Jin Qu hao UVA - 12563 (劲歌金曲)01背包,求装入的东西最多(相同多时价值大)

    题目:白书p274 题意:  KTV里面有n首歌曲你可以选择,每首歌曲的时长都给出了. 对于每首歌曲,你最多只能唱1遍. 现在给你一个时间限制t (t<=10^9) , 问你在最多t-1秒的时间 ...

  3. UVA 12563 劲歌金曲 Jin Ge Jin Qu hao

    劲歌金曲 Jin Ge Jin Qu hao 题面翻译 (如果当你看到这个标题的时候笑了,那么这个问题是为你准备的ヽ( ̄▽ ̄)ノ) 如果问一个麦霸:"你在KTV里必唱的曲目有哪些?" ...

  4. Jin Ge Jin Qu hao - UVa 12563 dp背包

    Problem J Jin Ge Jin Qu [h]ao (If you smiled when you see the title, this problem is for you ^_^) Fo ...

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

  6. UVA12563: Jin Ge Jin Qu hao(类01背包)

    Problem J Jin Ge Jin Qu [h]ao (If you smiled when you see the title, this problem is for you ^_^) Fo ...

  7. 例题 9-5 劲歌金曲(Jin Ge Jin Qu [h]ao Rujia Liu‘s Present 6, UVa 12563)

    原题链接:https://vjudge.net/problem/UVA-12563 分类:背包问题 备注:0-1背包变形 注意:千万不要包括给的时间t,因为劲歌金曲是必须要唱的! #include&l ...

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

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

  9. P1734 最大约数和 01背包变形

    传送门 思路:01背包变形题.将i看成重量,i的因子看成价值即可.背包自然是s. /** * From: * Qingdao Agricultural University * Created by ...

最新文章

  1. 运维常见统计表模板(word版)
  2. servlet session 跟踪用户上次访问时间
  3. python文件之间如何互相通信_不同的類和.py文件之間的python通信
  4. python docx 替换文字_在.docx文件-Python中查找和替换文本
  5. openNLP--Sentence Detector
  6. mysql5.7登陆时access denied解决办法
  7. 鱼骨图和甘特图图表合集PPT模板
  8. 弘辽科技:拼多多商品搜索热度如何提升?技巧分享
  9. 2008服务器远程开启,windows server 2008 r2中开启远程桌面的方法
  10. 四柱排盘系统--阳历转农历
  11. ar ebs 销售订单关闭_ZARA母公司拟关闭1200家门店,拿什么拯救快时尚品牌?
  12. 2022CCPC网络预选赛c题Problem C. Guess
  13. 测度、线性赋范空间、内积空间
  14. 怎么写出计算机SCI论文
  15. 618京东物流发大招,中小件完成了大陆地区的区县全面覆盖
  16. 【电磁场】矢量分析基础
  17. html整体垂直居中,实现HTML元素垂直居中的六种方法
  18. linux运行luminati,安装luminati的nodejs环境配置
  19. 定位的开启及特点(固定定位和粘滞定位)
  20. 智慧农业共享农场菜园,家禽果树认养小程序APP源码开发需要准备什么?

热门文章

  1. 深大uooc大学生心理健康章节答案第十一章
  2. 神经协同过滤Neural Collaborative Filtering(NCF)
  3. 微信小程序处理后台返回json
  4. 用html制作一个音乐排行榜,使用原生JavaScript制作一个漂亮的音乐播放器
  5. 理解ROM,PROM,EPROM,EEPROM,RAM,DRAM,SRAM,FLASH是什么
  6. java联机_Java实现简易联网坦克对战小游戏
  7. 数据库MySQL的使用,带GUI界面
  8. Unity GC问题刨析1--结构体
  9. 设置html的table高度100%
  10. 「kd指标」kd指标原理