HDU 3573 Buy Sticks (逻辑)】的更多相关文章

题意:a,b,c三种棍子长度分别为20,28,32,现需要这三种棍子数根,欲买长为75的棍子来剪成这三种(不够长的就废弃) ,问需要买多少根. 思路:将所有棍子尽可能和其他搭配起来,使得数量减到最少. 分情况:       结果(按最坏情况考虑): 2a+c=72 要么c=0,要么a=1或a=0 2a+b=68 要么b=0,要么a=1或a=0 2c=64    c=1或c=0 b+c=60       要么c=0,要么b=0 3a=60   a=2或 a=1 2b=56   b=0或b=1 最后…
Buy Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 868    Accepted Submission(s): 392 Problem Description Imyourgod need 3 kinds of sticks which have different sizes: 20cm, 28cm and 32cm…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2126 题意:给你n个物品,m元钱,问你最多能买个多少物品,并且有多少种解决方案. 一开始想到的是,先解决给m元钱因为我花的钱少就一定能购买够多的物品,因此是个贪心算法. 记买最多的物品数为c. 然后就是设计状态dp[i][j]代表我从前i个物品里花了j元钱,买c个物品有多少种方案. 后来发现状态维数不够,得重新想想. 于是就想到: 设计状态dp[i][j][k]代表我从前i个物品里买了j个,花的钱不…
题意:给出t组数据 每组数据给出n和m,n代表商品个数,m代表你所拥有的钱,然后给出n个商品的价值 问你所能买到的最大件数,和对应的方案数.思路: 如果将物品的价格看做容量,将它的件数1看做价值的话,那么用01背包就可以求的花费m钱所能买到的最大件数dp[m]. 但是题目还要求方案数,因此很容易想到再建立一个数组f[j],存储j元钱能买dp[j]个物品的方案数. 在求解01背包的过程中,要分两种情况讨论: 设当前所选的物品为i 1.   若选了物品i后,能买的件数比不选物品i的件数大,即dp[j…
Buy the souvenirs Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description When the winter holiday comes, a lot of people will have a trip. Generally, there are a lot of souvenirs to sell, and sometimes…
http://acm.hdu.edu.cn/showproblem.php?pid=1051 Problem Description There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs s…
Buy the souvenirs Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1662    Accepted Submission(s): 611 Problem Description When the winter holiday comes, a lot of people will have a trip. Genera…
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14126    Accepted Submission(s): 5842 Problem Description There is a pile of n wooden sticks. The length and weight of each stick a…
题解:每放一根棍子,都判断一下它与它前面的且在顶端的棍子是否相交,相交的话则将相应的棍子从解空间中除去. #include <cstdio> const double eps=1e-14; const int maxn=1e5+10; struct node{double x1,y1,x2,y2;int w;}e[maxn],f[maxn]; double cross(double x1,double y1,double x2,double y2){return x1*y2-x2*y1;} i…
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 22000    Accepted Submission(s): 8851 Problem Description There is a pile of n wooden sticks. The length and weight of each stick ar…
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5651    Accepted Submission(s): 2357 Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the nex…
题目链接:https://vjudge.net/contest/103424#problem/K 转载于:https://blog.csdn.net/acm_davidcn/article/details/5549933 题目大意: 给n个物品,和m块钱,输出能够购买最多物品的个数和购买这么多物品的方案数.  解题分析: 背包的一种进化版 , 除了记录最多能买多少个 , 需要记录买这么多个的方法 , 所以要在二维的基础上加多一维 . 状态转移方程如下 : f[i][j][k]=f[i-1][j-…
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)        Total Submission(s): 23527    Accepted Submission(s): 9551 There is a pile of n wooden sticks. The length and weight of each stick are known in a…
Pick-up sticks Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1872    Accepted Submission(s): 706 Problem Description Stan has n sticks of various length. He throws them one at a time on the fl…
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 10423    Accepted Submission(s): 4287 Problem Description There is a pile of n wooden sticks. The length and weight of each stick ar…
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4185    Accepted Submission(s): 1759 Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next…
Buy Tickets Time Limit : 8000/4000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Total Submission(s) : 31   Accepted Submission(s) : 15 Problem Description Railway tickets were difficult to buy around the Lunar New Year in China, so we m…
题意: 给出一些纪念品的价格,先算出手上的钱最多能买多少种东西k,然后求手上的钱能买k种东西的方案数.也就是你想要买最多种东西,而最多种又有多少种组合可选择. 思路: 01背包.显然要先算出手上的钱m最多能买多少种东西k,可以从价格最少的纪念品买起,看最多能买多少种,置为k.接下来按照常规01背包计算,需要记录下方案数和组成的物品数,看代码就会懂的. #include <iostream> #include <stdio.h> #include <cstring> #i…
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7152    Accepted Submission(s): 2998 Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the nex…
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8838    Accepted Submission(s): 3684 Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next…
题意: 有 n 根木棒,长度和质量都已经知道,需要一个机器一根一根地处理这些木棒. 该机器在加工过程中需要一定的准备时间,是用于清洗机器,调整工具和模板的. 机器需要的准备时间如下: 1.第一根需要1min的准备时间: 2.在加工了一根长为 l ,重为 w 的木棒后,接着加工一根长为 l’(l <= l’),重为 w’ (w <= w’)的木棒是不需要任何准备时间的,否则需要1min时间. 求加工 n 根木棒所用的最少时间.例如现有长和重分别为(4,9),(5,2),(2,1),(3,5)和(…
题意:给出n个木头的重量wi,长度li,如果满足w[i+1]>=w[i]且l[i+1]>=l[i],则不用耗费另外的加工时间,问至少需要多长时间加工完这些木头. 第一次做这一题目也没有做出来---而且也是好久以前---于是又看题解了--- 发现和将木材按两个关键字(先按重量由大到小排,如果重量相等的话则按长度由大到小排)排序后,和导弹拦截系统是一样的了,求长度的最长上升子序列. 自己写的二分查找一直输不出结果----555555 后来用了题解里面的lower_bound函数 搜了一点lower…
首先,记50的为0,100的为1. 当m=4,n=3时,其中的非法序列有0110010; 从不合法的1后面开始,0->1,1->0,得到序列式0111101 也就是说,非法序列变为了n-1个0,m+1个1. 总的数目=C(m+n,n),非法的=C(m+n,m+1) 符合数目=(C(m+n,n)-C(m+n,m+1))*m!*n!; 化简得:(m+n)!*(m+1-n)/(m+1). Java代码: import java.io.*; import java.math.*; import jav…
Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next few days. As a crazy fan of Harry Potter, you will go to the cinema and have the first sight, won't you? Suppose the cinema only has one ticket-office and…
一道不算复杂的线段树,就是数据处理需要好好想一下. 将输入的所有数据从后往前输入,对于最后一个值,如果它想插入第i个位置,那么他就必须在前面留下i-1个位置.对于倒数第二个人,如果他想插入j位置,那么在他前面就应该有j-1个空位置.他在最后一个人前面还是后面根本不重要,重要的是他必须在第j个空位.这个要好好想一下. 线段树节点存储的是当前区间的空位置的数量. #include<stdio.h> #include<string.h> #define N 200005 struct n…
题目链接>>> 转载于:https://www.cnblogs.com/Action-/archive/2012/07/03/2574800.html  题目大意: 给n根木棍的长度和重量.根据要求求出制作木棍的最短时间.建立第一个木棍需要1分钟,若是接着要制作的木棍重量和长度都比此木棍长就不需要建立的时间,若是没有,则再需要建立时间.求时间最小为多少. 解题思路: 对木棍的长度和重量进行排序,以长度为首要考虑.排序完后的不一定都是下一根木棍重量和长度都大于前一根的.于是,我们对排序后的…
本题一看就知道是最长不减序列了,一想就以为是使用dp攻克了. 只是那是个错误的思路. 我就动了半天没动出来.然后看了看别人是能够使用dp的,只是那个比較难证明其正确性,而其速度也不快.故此并非非常好的解决方法. 所以我就直接硬算.硬模拟选择出非减子序列,选完就出答案了. 思路: 1 依照长度排序 2 依照不减原则选择重量,选一个,消灭一个. 最后消灭完了,就处理完成,答案就自然出来了. 原来是一道披着dp的外套的模拟题啊!一道伪装成难题的简单题. 代码也能够写的非常简洁: #include <s…
设50元的人为+1 100元的人为-1 满足前随意k个人的和大于等于0 卡特兰数 C(n+m, m)-C(n+m, m+1)*n!*m! import java.math.*; import java.util.*; public class Main { /** * @param args */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int cas = 1; while(tru…
题目链接 题意 : 给出一些数.你可以从左到右对这些数进行三种操作花费 Ai 买入东西.以 Ai 价格卖出你当前有的东西.或者什么都不做.现在问你可以获取的最大利益是多少? 分析 : 和 CF 867E 一模一样 传送门 可以去搜这题的题解.有很多 对于每个元素产生的贡献 可以先算出暂时的最优值 如果下次碰到更优的选择再进行替换 具体就是首先使用小顶堆维护枚举过的元素 然后对于当前枚举到的元素 用它和堆顶元素做对比.如果小于或等于堆顶元素 那么它无法和之前枚举过的所有元素的任何一个做减法产生贡献…
#include <iostream>#include<stdio.h>#include<cmath>#include<algorithm>using namespace std;struct product{    int w;    int l;     bool operator<(product &p2)    {        if(w==p2.w)return l<=p2.l;        else return w<…