UVA 12563 劲歌金曲(01背包)】的更多相关文章

劲歌金曲 [题目链接]劲歌金曲 [题目类型]01背包 &题解: 题意:求在给定时间内,最多能唱多少歌曲,在最多歌曲的情况下,使唱的时间最长. 该题类似于01背包问题,可用01背包问题的解题思路来求,每个歌曲相当于物品,歌曲的长度相等于物品重量,每个歌曲的"价值"为1.由于金歌劲曲时间最长,所以最后要留至少1秒时间开始唱金歌劲曲,所以计算t-1时间内最多唱的歌曲和时间,最终答案为歌曲数加1,时间加上金歌劲曲的时间.这里我使用滚动数组计算这个值, 用len记录t-1. 需要注意的是…
https://vjudge.net/problem/UVA-12563 题意: 在一定的时间内连续唱歌,最后一首唱11分钟18秒的劲歌金曲,问最多能长多长时间. 思路: 0-1背包问题,背包容量为t-1,因为至少还要留1秒钟来放劲歌金曲.还需要注意的是题目要求的是在唱最多首歌的情况下所能唱的最长时间,所以这里我们来限制一下时间,对于j时刻,我们要求正好唱完这首歌,那么这样唱的歌肯定是最多的. #include<iostream> #include<algorithm> #incl…
Problem J Jin Ge Jin Qu [h]ao (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…
UVA.10130 SuperSale (DP 01背包) 题意分析 现在有一家人去超市购物.每个人都有所能携带的重量上限.超市中的每个商品有其相应的价值和重量,并且有规定,每人每种商品最多购买一个.求这一家人所能购买到的最大价值是多少. 每个人的所能携带的最大重量即为背包容量.此题只是换成n个人而已.所以分别以每个人最大携带重量为背包容量,对所有商品做01背包,求出每个人的最大价值.这些最大价值之和即为这家人购物的最大价值. 核心状态转移方程: dp[i][j] = max(dp[i][j],…
01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 ],dp[N]; int…
01背包,由于要输出方案,所以还要在dp的同时,保存一下路径. #include <iostream> #include <stdio.h> #include <string.h> /* AC 01背包+输出方案 答案不唯一,就像样例中的 45 8 4 10 44 43 12 9 8 2 题目给出的输出4 10 12 9 8 2 sum:45 输出43 2 sum:45 也是可以的 题目中没要求按照什么顺序输出,输出一种方案即可 */ using namespace s…
//平分硬币问题 //对sum/2进行01背包,sum-2*dp[sum/2] #include <iostream> #include <cstring> #include <algorithm> using namespace std; ],dp[]; int main() { int n,m,sum,sum1; cin>>n; while(n--) { cin>>m; sum=; ;i<=m;i++) { cin>>val…
CD You have a long drive by car ahead. You have a tape recorder, but unfortunately your best music is on CDs. You need to have it on tapes so the problem to solve is: you have a tape N minutes long. How to choose tracks from CD to get most out of tap…
  CD  You have a long drive by car ahead. You have a tape recorder, but unfortunately your best music is on CDs. You need to have it on tapes so the problem to solve is: you have a tape N minutes long. How to choose tracks from CD to get most out of…
<题目链接> 题目大意: 你要录制时间为N的带子,给你一张CD的不同时长的轨道,求总和不大于N的录制顺序 解题分析: 01背包问题,需要注意的是如何将路径输出. 由于dp时是会不断的将前面所选物品更新的,所以我们输出路径时,应该倒序,将用过的物品减去,才能得到正确的路径. #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> using name…