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…
紫书P274 题意:输入N首歌曲和最后剩余的时间t,问在保证能唱的歌曲数目最多的情况下,时间最长:最后必唱<劲歌金曲> 所以就在最后一秒唱劲歌金曲就ok了,背包容量是t-1,来装前面的歌曲,设两个Time求时间,cnt是数量 #include <iostream> #include <cstring> #include <algorithm> #include <cstdio> using namespace std; const int MAX…
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…
分析可知,虽然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…
(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…
• 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. 每首歌唱一次,在一定时间类,要求唱歌数量尽量多,时间尽量长.而且…
题目链接:Knapsack problem 大意:给出T组测试数据,每组给出n个物品和最大容量w.然后依次给出n个物品的价值和体积. 问,最多能盛的物品价值和是多少? 思路:01背包变形,因为w太大,转而以v为下标,求出价值对应的最小体积,然后求出能够满足给出体积的最大价值. 经典题目,思路倒是挺简单的,就是初始化总觉得别扭...T_T大概,因为我要找的是最小值,所以初始化为maxn,就结了? 这个问题好像叫01背包的超大背包... 模拟一下样例吧! 1 5 15 // 初始化为dp[0] =…
01背包变形,注意dp过程的时候就需要取膜,否则会出错. 代码如下: #include<iostream> #include<cstdio> #include<cstring> using namespace std; #define MAXW 15005 #define N 155 #define LL long long #define MOD 1000000007 int w1[N],w2[N]; LL dp1[MAXW],dp2[MAXW]; int main(…
Bone Collector II Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4739    Accepted Submission(s): 2470 Problem Description The title of this problem is familiar,isn't it?yeah,if you had took pa…
http://acm.hdu.edu.cn/showproblem.php?pid=2955 [题意] 有一个强盗要去几个银行偷盗,他既想多抢点钱,又想尽量不被抓到.已知各个银行 的金钱数和被抓的概率,以及强盗能容忍的最大被抓概率.求他最多能偷到多少钱? [思路] 01背包:每个物品代价是每个银行钱的数目,物品的价值是在该银行不被抓的概率 (1-被抓概率),背包容量是所有银行钱的总和.01背包求dp[i]表示获得i的钱不被抓的最大概率.最后从大到小枚举出 dp[i]>=(1-P)这个i就是答案了…