{POJ}{3971}{Scales}{O(N)动态规划}】的更多相关文章

题意:给定一堆2二进制砝码,给定一个物品,要求在天平两端加入物品和砝码使之平衡,求可能数. 思路:一开始想到了直接用数学原理,结果没证出来.做如下思考,此题需要用二进制: (1)设物品重量为w,加入的砝码重量为x,另一边重量为y,便有w+x=y. (2)另外,假如物品为100110,加入的砝码可以为000010,那么总和为101000,显然x与y不能有位数相同的1(因为每种砝码只有一个),因此便有x&y=0 依据这两点,可以知道此题的关键之处就在于如何分析w+x的进位情况.分析物品的第i位,比如…
POJ.3172 Scales (DFS) 题意分析 一开始没看数据范围,上来直接01背包写的.RE后看数据范围吓死了.然后写了个2^1000的DFS,妥妥的T. 后来想到了预处理前缀和的方法.细节以注释的方式给出. 代码总览 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <sstream> #include <s…
http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 32923   Accepted: 19514 Description 73 88 1 02 7 4 44 5 2 6 5 (Figure 1) Figure 1 shows a number triangle. Write a program that calculates the hi…
题目链接:http://poj.org/problem?id=1787 题意:有4种货币分别是1元,5元,10元,20元.现在告诉你这四种货币分别有多少个,问你正好凑出P元钱最多可以用多少货币.每种货币要用多少钱. 据说此题有完全背包的写法.. 我是按照多重背包写的,速度也不是很慢. 然后记录了下前驱. 刚开始全都写挫了..虽然现在也很挫.. 凑合着看吧 -- #include <cstdio> #include <algorithm> #include <cstring&g…
题目地址:http://poj.org/problem?id=1080 Description It is well known that a human gene can be considered as a sequence, consisting of four nucleotides, which are simply denoted by four letters, A, C, G, and T. Biologists have been interested in identifyi…
题目地址:http://poj.org/problem?id=1050 Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous sub-array of size 1*1 or greater located within the whole array. The sum of a rectangle is the sum of a…
题目传送门 POJ 1458 Description A subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = < x1, x2, ..., xm > another sequence Z = < z1, z2, ..., zk > is a subsequence of X if there ex…
一.题目 The Triangle 二.分析 动态规划入门题. 状态转移方程$$DP[i][j] = A[i][j] + max(DP[i-1][j], DP[i][j])$$ 三.AC代码 1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <algorithm> 5 #include <vector> 6 #include <cmath>…
Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous sub-array of size 1*1 or greater located within the whole array. The sum of a rectangle is the sum of all the elements in that rectangle. I…
题意:给定 n 个数,保证下一个数比上一个数和前一个数之和大,然后给定一个背包,问你最多放多少容积. 析:应该是很明显的01背包,但是可惜的是,数组开不出来,那就得考虑暴力,因为数不多,才几十而已,要不然就超int了,然后我就暴力做了,超时了, 这个还是前剪枝的,这样剪的,先把前几项和算出来,确定最大砝码的重量,然后在暴力时,如果发现剩下的比总和还小,或者等于,就不用再算了,直接结束就好了, 这样做时间竟然是0毫秒,可能是标程吧,并不是很理解为什么是0. 代码如下: #include <cstd…
思路:dp[i]=min{dp[j]+max(num[j+1]...num[i])},其中sum[i]-sum[j]<=m. 那么我们需要用单调队列维护j到i的最大值. #include<set> #include<map> #include<cmath> #include<queue> #include<cstdio> #include<vector> #include<string> #include<cs…
思路:我们首先来一遍拓扑排序,将点按先后顺序排列于一维数组中,然后扫描一遍数组,将每个点的出边所连接的点进行更新,即可得到最优解. #include<iostream> #include<cstdio> #include<cstring> #include<queue> #include<algorithm> #define inf 2000000010 #define Maxn 100010 #define Maxm 1000010 using…
炮兵阵地 Description 司令部的将军们打算在N*M的网格地图上部署他们的炮兵部队.一个N*M的地图由N行M列组成,地图的每一格可能是山地(用"H" 表示),也可能是平原(用"P"表示),如下图.在每一格平原地形上最多可以布置一支炮兵部队(山地上不能够部署炮兵部队):一支炮兵部队在地图上的攻击范围如图中黑色区域所示: 如果在地图中的灰色所标识的平原上部署一支炮兵部队,则图中的黑色的网格表示它能够攻击到的区域:沿横向左右各两格,沿纵向上下各两格.图上其它白色网…
Post Office Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 15412   Accepted: 8351 Description There is a straight highway with villages alongside the highway. The highway is represented as an integer axis, and the position of each villa…
其实这个题目要是注意到了题目的一点关键性的描述就会变得很简单,题意是给出的砝码是至少是前两个的和的,有了这一点,那么砝码的数量应该就在几十左右,这样的话适当剪枝的搜索是应该可以过的. #include <iostream> #include <cstdio> #include <cstring> using namespace std; const int maxn=1e3+9; unsigned int a[maxn]; int n,c; long long ans,…
Description A straight dirt road connects two fields on FJ's farm, but it changes elevation more than FJ would like. His cows do not mind climbing up or down a single slope, but they are not fond of an alternating succession of hills and valleys. FJ…
We have received an order from Pizoor Communications Inc. for a special communication system. The system consists of several devices. For each device, we are free to choose from several manufacturers. Same devices from two manufacturers differ in the…
Travel Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4353   Accepted: 1817 Description One traveler travels among cities. He has to pay for this while he can get some incomes. Now there are n cities, and the traveler has m days for tra…
The Cow Lexicon Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8167   Accepted: 3845 Description Few know that the cows have their own dictionary with W (1 ≤ W ≤ 600) words, each containing no more 25 of the characters 'a'..'z'. Their c…
动态规划与贪心相关: {HDU}{4739}{Zhuge Liang's Mines}{压缩DP} 题意:给定20个点坐标,求最多有多少个不相交(点也不相交)的正方形 思路:背包问题,求出所有的正方形,然后求最多有多少个正方形不互相覆盖,这题真是神思路. {POJ}{3846}{Mountain Road} 题意:给定两个地点车的班次,路是双向单车道,求安排最短的时间 思路:对车次序列进行二维DP转移,转移的时候需要注意时刻的维护.这个题目的DP思路是正向DP,每次遍历到f[i][j]都需要更新…
OJ上的一些水题(可用来练手和增加自信) (POJ 3299,POJ 2159,POJ 2739,POJ 1083,POJ 2262,POJ 1503,POJ 3006,POJ 2255,POJ 3094) 初期: 一.基本算法: 枚举. (POJ 1753,POJ 2965) 贪心(POJ 1328,POJ 2109,POJ 2586) 递归和分治法. 递推. 构造法.(POJ 3295) 模拟法.(POJ 1068,POJ 2632,POJ 1573,POJ 2993,POJ 2996) 二…
著名题单,最初来源不详.直接来源:http://blog.csdn.net/a1dark/article/details/11714009 OJ上的一些水题(可用来练手和增加自信) (POJ 3299,POJ 2159,POJ 2739,POJ 1083,POJ 2262,POJ 1503,POJ 3006,POJ 2255,POJ 3094) 初期: 一.基本算法: 枚举. (POJ 1753,POJ 2965) 贪心(POJ 1328,POJ 2109,POJ 2586) 递归和分治法. 递…
[转] POJ推荐50题以及ACM训练方案 -- : 转载自 wade_wang 最终编辑 000lzl POJ 推荐50题 第一类 动态规划(至少6题, 和 必做) 和 (可贪心) (稍难) 第二类 搜索(至少4题) (稍难,也可并查集) 第三类 贪心(至少2题) (难) 第四类 最短路 (至少3题) Bellman-Ford (难) 第五类 最小生成树 (至少2题, 而且 Prim 和 Kruskal 至少各用一次) 第六类 最大流 (至少2题) (最小费用最大流) (难) 第七类 二分图…
1.TreeMap和TreeSet类:A - Language of FatMouse ZOJ1109B - For Fans of Statistics URAL 1613 C - Hardwood Species POJ 2418D - StationE - Web Navigation ZOJ 1061F - Argus ZOJ 2212G - Plug-in2.SegmentTreeA-敌兵布阵 hdu 1166B - I Hate It HDU 1754C - A Simple Pro…
此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276,1322, 1414, 1456, 1458, 1609, 1644, 1664, 1690, 1699, 1740(博弈),1742, 1887, 1926(马尔科夫矩阵,求平衡), 1936, 1952, 1953, 1958, 1959, 1962, 1975,…
[1]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 1322, 1414, 1456, 1458, 1609, 1644, 1664, 1690, 1699, 1740(博弈), 1742, 1887,1926(马尔科夫矩阵,求平衡), 1936, 1952, 1953, 1958, 1959, 1962, 1975, 1989, 2018, 2029,…
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4098409.html 题目链接:poj 3783 Balls 动态规划 100层楼投鸡蛋问题 使用动态规划算法,使用$dp[i][j]$表示对于i层楼并拥有$j$个鸡蛋时能够判断鸡蛋质量需要的最少次数.假如我们在第$k$层扔下一个鸡蛋,则有两种情况,如果鸡蛋没有损坏则问题相当于我们对于$i-k$层楼拥有$j$个鸡蛋所需的最少的次数.如果鸡蛋损坏了,则问题相当于对于k层楼拥有$j-1$个鸡蛋…
题目链接:http://poj.org/problem?id=3181 题目大意:用1,2...K元的硬币,凑成N元的方案数. Sample Input 5 3 Sample Output 5 分析:这不是母函数是什么,不管你信不信,反正我是信了. 之前有过一篇,讲母函数的动态规划做法http://www.cnblogs.com/acm-bingzi/archive/2013/04/30/3051725.html 这道题目,坑就坑在高精度上了,刚开始怎么也没想到,而且做法也很奇特.就是将2个lo…
题目链接: http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1033 http://poj.org/problem?id=1141 ZOJ目前挂了. 题目大意: 给一个括号序列,要求输出,最少增加括号数情况下,任意一个合法括号序列即可. 匹配是指()和[]完全合法,可以嵌套. 题目思路: [动态规划] 区间DP,枚举左右区间端点,两种匹配方法:中间拆开匹配或者直接头尾匹配. 转移得到最优值,同时记录得到最优值的方法,最后逆推得到不用增加的括号位置…
]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 1322, 1414, 1456, 1458, 1609, 1644, 1664, 1690, 1699, 1740(博弈), 1742, 1887, 1926(马尔科夫矩阵,求平 衡), 1936,1952, 1953, 1958, 1959, 1962, 1975, 1989, 2018, 2029,2…