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 e…
• 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. 每首歌唱一次,在一定时间类,要求唱歌数量尽量多,时间尽量长.而且…
InputThe first line contains the number of test cases T (T ≤ 100). Each test case begins with two positiveintegers 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 cont…
(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…
分析可知,虽然t<109,但是总曲目时间大于t,实际上t不会超过180*n+678.此问题涉及到两个目标信息,首先要求曲目数量最多,在此基础上要求所唱的时间尽量长.可以定义 状态dp[i][j]表示前i首歌曲,恰好唱的时间为j时,所唱的最长时间,于是就是裸的01背包了. /*----UVa12563 Jin Ge Jin Qu */ #define _CRT_SECURE_NO_DEPRECATE #include<iostream> #include<vector> #in…
继续战dp.不提. 题意分析 这题说白了就是一条01背包问题,因为对于给定的秒数你只要-1s(emmmmm)然后就能当01背包做了——那1s送给劲歌金曲(?).比较好玩的是这里面dp状态的保存——因为要满足两个条件,因此我们的状态的定义也随之改变,使用自定义的结构体来保存.这个是我以前从来没接触过也没想到的.非常高级了,记下来.感谢想到的dalao! 代码 #include <set> #include <cmath> #include <queue> #include…
这是一道不错的题.首先通过分析,贪心法不可取,可以转化为01背包问题.但是这过程中还要注意,本题中的01背包问题要求背包必须装满!这就需要在普通的01背包问题上改动两处,一个是初始化的问题:把dp[0]初始化为0,而其它的dp值都初始化为-1,表示不符要求.为什么这么初始化?背包九讲里说到:“初始化的dp数组事实上就是在没有任何物品可以放入背包时的合法状态.如果要求背包恰好装满,那么此时只有容量为0的背包可能被价值为0的nothing“恰好装满”,其它容量的背包均没有合法的解,属于未定义的状态,…
这道题其实是一道01背包的变形题,主要思路如下:在不把剩余时间用光的前提下(剩余时间>0),尽可能的多唱歌.于是我们可以用dp[i]表示的是到当前i秒时,最多可以唱多少歌. 状态转换方程:dp[k]=max(dp[k],dp[k-yy]+1);最后输出可以唱多少歌. #include<bits/stdc++.h> using namespace std; int n,t,m,yy; ]; int main() { cin>>n; ;i<=n;i++) { memset(…
题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4008 题目大意: 想象一下,你在KTV,想待久点,并且机器会让你唱完你歌再停.于是你选了劲歌金曲,678秒.现在你至少还剩一秒切到这首歌,而且每首歌必须唱完,现在问你你最久能待多久. 思路: 01背包,动态规划.但是01背包变式我第一次做的时候没有想到,结果误入歧途..后面会贴…
[Link]: [Description] KTV给你T秒的唱歌时间; 你有n首一定要唱的歌; 然后有一首很变态的歌有678s,你想在T秒结束之前唱一下这首歌; 因为这样的话,你能尽量晚地走出KTV(不会在你唱到一半的时候让你不唱了),即你最后的唱歌时间是可以超过T秒的; 告诉你n首歌的时间; 这n首歌里面任选几道唱,但必须要留一点时间唱那首变态的歌; 问你最多能唱多少首歌,然后在唱歌最多的基础上,问你最晚能什么时候走出KTV [Solution] 如果∑a[i]<T的话,则直接输出答案n+1和…