爱丽丝喜欢集邮.她现在在邮局买一些新邮票. 世界上有各种各样的邮票;它们的编号是1到N.但是,邮票不是单独出售的;必须成套购买.有M套不同的邮票可供选择; 第i套包括编号从li到ri的邮票 .同一枚邮票可能会出现在不止一套邮票中,而且可能在任何一套邮票中都找不到一枚或多枚邮票. 所有套装的价格都是一样的;因为爱丽丝的预算有限,她最多只能买K套不同的邮票.爱丽丝最多能买到多少种不同的邮票? Input 输入从一行开始,其中包含一个整数T,即测试用例的数量.接下来是T测试用例. 每个测试用例都以一行…
题目链接 HDU 6249 题意 给定$m$个区间,在这些区间中选出不超过$k$个,求被覆盖的点的数量的最大值. 设$f[i][j]$表示选到第$i$个点并选了$j$个区间的时候能得到的最大答案. 处理到第$i$个点的时候观察所有覆盖$i+1$这个点的线段,找到延伸到最右端的这条线段. 假设该线段延伸到$r$,那么更新$f[r][j + 1]$. 最后枚举答案即可. #include <bits/stdc++.h> using namespace std; #define rep(i, a,…
http://acm.hdu.edu.cn/showproblem.php?pid=6249 题意: 给出n个区间,求选k个区间的最大区间并. 思路: 可能存在左端点相同的多个区间,那么此时我们肯定选右端点最大的那个区间.现在将区间按左端点排序,d[i][j]表示在1-i坐标轴范围内选择j个区间的最大区间并. 状态转移方程如下: dp[i+][j] = max(dp[i][j],dp[i+][j]); //不选的话就和上一个一样 dp[i+num][j+] = max(dp[i][j]+num,…
/*有n件物品,旅客一共有m块大洋.第一个问题,旅客最多可以买多少件物品?请注意,这里是多少件,不是价值最大.所以这个非常好求,将所有的物品按照价值排序,先买便宜的,再买贵的.贪心的思想.这个地方有些细节需要处理,如果所有物品的价值总和比旅客的钱少,那么就只有一个方案,旅客可以买走所有的物品.如果旅客的钱数连第一件物品都买不起,那么就直接输出"Sorry,you  can't buy anything.". 用这种方法,我们可以求出旅客最多买多少件物品,求出之后,物品的价格就有了两种属…
题目大意: 根据学校的申请费用,根据已有的钱得到最大的offer率 这里很明显就是一个价值为概率的背包问题 计算两个offer合并的概率 为a + b - a*b #include <cstdio> #include <cstring> #include <iostream> using namespace std; ; double dp[N]; int main() { int n , m , a; double b; while(scanf("%d%d&…
需要按照B/C的值从大到小排序. #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> #include<queue> #include<vector> #include<map> using namespace std; typedef long long LL; ; ; ; int…
Description ACboy has N courses this term, and he plans to spend at most M days on study.Of course,the profit he will gain from different course depending on the days he spend on it.How to arrange the M days for the N courses to maximize the profit? …
Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also he went to the grave … The bone collector had a big bag with a volume of…
[题目链接] 题目大意: 说有$m$个区间,要求选出不超过$k$个区间,使这些区间覆盖的长度最长,问最长长度是多少. 题解: 所有区间按$R$从小到大排序之后可以进行$dp$. $dp[i][j]$表示:拿了小于等于$i$个区间,最后一个以坐标小于等于$j$为结尾的最长覆盖长度 假设第$x$个区间作为结尾,那么要分两种情况来考虑: 1.可以是之前的结尾小于第$x$个区间的左端点,这种情况很好解决. 2.也可以是之前区间的结尾在第$x$个区间内部. 第二种情况的话: 不允许在区间内部进行枚举点,否…
Alice’s Stamps Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 125    Accepted Submission(s): 34 Problem Description Alice likes to collect stamps. She is now at the post office buying some new…
点击传送 Alice’s Stamps Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1448    Accepted Submission(s): 501 Problem Description Alice likes to collect stamps. She is now at the post office buying so…
题意:标号为1-n的n种邮票,m个邮票集,每个集里有标号从Li到Ri的邮票,要从中选K个邮票集,使这K个邮票集能覆盖最多种的邮票,问最多能覆盖多少种邮票 思路:区间DP (我:??? f[i][j]表示从1 - i 位置选择 j 个集合的覆盖种数 首先它可以从f[i][j] = max(f[i][j], max(f[i-1][j], f[i][j-1]))转移来 其次考虑它能转移到的点 用up[i] 记录覆盖i点的线段最右的点,如果要在 i 后面加一条线段,那么肯定优先取这个(因为它最右,同样加…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114 Piggy-Bank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 32136    Accepted Submission(s): 15965 Problem Description Before ACM can do anythi…
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 27961    Accepted Submission(s): 9847 Problem Description Nowadays, we all know that Computer College is the biggest department…
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 30163    Accepted Submission(s): 13507 Problem Description Nowadays, a kind of chess game called “Super Jumping!…
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 31458    Accepted Submission(s): 14128 Problem Description Nowadays, a kind of chess game called “Super Jumping!…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5125 题解: 这个题dp[i][0],dp[i][1]数组分别记录在第i个位置取a[i]和b[i]时可以取到最长上升子序列的长度,然后开一个m[i][0]和m[i][1]分别表示取到第i个位置时最少的交换次数.然后进行4次比较,最后取最大值的时候非常巧妙,如果m[i][0]>M,那么证明这个序列里面多了 m[i][0]-M 个数,所以要减掉这么多个数. 蒟蒻感觉别人好强啊.... #include…
给一个数列,问最少修改多少个元素使数列严格递增.如果不是要求“严格”递增,那就是求最长不降子序列LIS,然后n-LIS就是答案.要严格递增也好办,输入的时候用每个数减去其下标处理一下就行了. /* * Author : ben */ #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <iostr…
Advanced Fruits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2358    Accepted Submission(s): 1201Special Judge Problem Description The company "21st Century Fruits" has specialized in cr…
[抄题]: You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the…
Human Gene Functions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3008    Accepted Submission(s): 1701 Problem Description It is well known that a human gene can be considered as a sequence,…
Jack's struggle Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 1418    Accepted Submission(s): 471 Problem Description A team of airborne troops are ready to complete some missions.The battlef…
反恐训练营 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4064    Accepted Submission(s): 967 Problem Description 当 今国际反恐形势很严峻,特别是美国“9.11事件”以后,国际恐怖势力更是有恃无恐,制造了多起骇人听闻的恐怖事件.基于此,各国都十分担心恐怖势力会对 本国社会造成的不稳…
Fibonacci Tree Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4136    Accepted Submission(s): 1283 Problem Description Coach Pang is interested in Fibonacci numbers while Uncle Yang wants him t…
变形课 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 18343    Accepted Submission(s): 6597 Problem Description 呃......变形课上Harry碰到了一点小麻烦,由于他并不像Hermione那样可以记住全部的咒语而任意的将一个棒球变成刺猬什么的,可是他发现了变形咒语的一个统一…
/*关于最小生成树的等效边,就是讲两个相同的集合连接在一起 先建立一个任意最小生成树,这条边分开的两个子树的节点最大的一个和为A,sum为最小生成树的权值和,B为sum-当前边的权值 不断枚举最小生成树中的边找最优值即可. */ #include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #define N 1100 struct nodee { int u,v; doub…
Recently, Shua Shua had a big quarrel with his GF. He is so upset that he decides to take a trip to some other city to avoid meeting her. He will travel only by air and he can go to any city if there exists a flight and it can help him reduce the tot…
这段时间看了<背包九讲>,在HUST VJUDGE上找到了一个题单,挑选了其中16道题集中做了下,选题全部是HDU上的题,大多是简单题.目前做了点小总结,大概提了下每道题的思路重点部分,希望以后回看回想时能有帮助. 题单:http://vjudge.net/contest/22694#overview 题单列表 HDU 1059.HDU 1114.HDU 1171.HDU 1203.HDU 1712.HDU 2159. HDU 2191.HDU 2546.HDU 2602.HDU 2639.H…
悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 HDU 2191 一道裸的多重背包问题: #include<iostream> #include<algorithm> #include<stdio.h> #include<string.h> using namespace std; ],a[],b[],c[]; int main() { int t,n,m; scanf("%d",&t); while(t--) { scanf…
湫湫系列故事――减肥记I  HDU 4508 一道裸的完全背包 #include<iostream> #include<algorithm> #include<stdio.h> #include<string.h> using namespace std; ],a[],b[]; int main() { int n,i,j,m; while(scanf("%d",&n)!=EOF) { ;i<n;i++) scanf(&qu…