thanks prof. Abhiram Ranade for his vedio on Longest Common Subsequence 's back track search view in lecture 19, nice explanation indeed. // back track, recursive, 390 ms, O(m*n) memory #include <cstdio> #include <vector> #include <string&g…
Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1869    Accepted Submission(s): 777 Special Judge Problem Description Your old uncle Tom inherited a piece of land fr…
Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 11706    Accepted Submission(s): 3219 Problem Description A histogram is a polygon composed of a sequence of rec…
胜利大逃亡(续) Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 22   Accepted Submission(s) : 10 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王喜…
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 70032    Accepted Submission(s): 19286 Problem Description The doggie found a bone in an ancient maze, which fascinated him a…
reference: 6.4 knapsack in Algorithms(算法概论), Sanjoy Dasgupta University of California, San Diego Christos Papadimitriou University of California at Berkeley Umesh Vazirani University of California at Berkeley the unbounded knapsack and 0-1 knapsack a…
a typical variant of LCS algo. the key point here is, the dp[][] array contains enough message to determine the LCS, not only the length, but all of LCS candidate, we can backtrack to find all of LCS. for backtrack, one criteria is dp[i-1][j]==dp[i][…
one recursive approach to solve hdu 1016, list all permutations, solve N-Queens puzzle. reference: the video of stanford cs106b lecture 10 by Julie Zelenski https://www.youtube.com/watch?v=NdF1QDTRkck // hdu 1016, 795MS #include <cstdio> #include &l…
A simple problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3702 Accepted Submission(s): 1383 Problem Description Zty很痴迷数学问题..一天,yifenfei出了个数学题想难倒他,让他回答1 / n.但Zty却回答不了^_^. 请大家编程帮助他. Input 第一行…
A + B Problem Too Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 13465    Accepted Submission(s): 10008 Problem Description This problem is also a A + B problem,but it has a little difference,…
three version are provided. disjoint set, linked list version with weighted-union heuristic, rooted tree version with rank by union and path compression, and a minor but substantial optimization for path compression version FindSet to avoid redundanc…
for the backtracking part, thanks to the video of stanford cs106b lecture 10 by Julie Zelenski for the nice explanation of recursion and backtracking, highly recommended. in hdu 2553 cout N-Queens solutions problem, dfs is used. // please ignore, bel…
huffman coding, greedy algorithm. std::priority_queue, std::partition, when i use the three commented lines, excution time increase to 15ms from 0ms, due to worse locality? thanks to http://acm.hdu.edu.cn/discuss/problem/post/reply.php?action=support…
thanks to http://acm.hdu.edu.cn/discuss/problem/post/reply.php?action=support&postid=19638&messageid=1&deep=0 for the test case provided. below is an excerpt data 8 11 9 8 8 8 4 3 2 11 8 8 8 8 4 3 2 answer 800 #include <cstdio> #include…
thanks to http://stackoverflow.com/questions/2144459/using-scanf-to-accept-user-input and http://stackoverflow.com/questions/456303/how-to-validate-input-using-scanf for the i/o part. thanks to http://www.haodaima.net/art/137347 for the rounding part…
RGCDQ Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice HDU 5317 Appoint description: Description Mr. Hdu is interested in Greatest Common Divisor (GCD). He wants to find more and more interesting things abou…
problem description http://acm.hdu.edu.cn/showproblem.php?pid=1030 #include <cstdio> #include <cmath> #include <algorithm> int calPathLength(int x, int y) { //path length from 1 (1st line, lower) to a number in ith line is only differ by…
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 34556    Accepted Submission(s): 11986 Problem Description Nowadays, we all know that Computer College is the biggest departmen…
Happy Programming Contest Time Limit: 2 Seconds      Memory Limit: 65536 KB In Zhejiang University Programming Contest, a team is called "couple team" if it consists of only two students loving each other. In the contest, the team will get a lov…
reference: Rabin-Karp and Knuth-Morris-Pratt Algorithms By TheLlama– TopCoder Member https://www.topcoder.com/community/data-science/data-science-tutorials/introduction-to-string-searching-algorithms/ // to be improved #include <cstdio> #include <…
use fgets, and remove the potential '\n' in the string's last postion. (main point) remove redundancy there must be a stack, at first sight, you need a stack of type myNode, but think deeper, matrix multiplication is valid only if A.c=B.r, then the n…
the algorithm of three version below is essentially the same, namely, Kadane's algorithm, which is of O(n) complexity. https://en.wikipedia.org/wiki/Maximum_subarray_problem the evolution of the implementations is to remove redundancy and do what is…
use sentinel to avoid boudary testing, use swap trick to avoid extra copy. original version #include <cstdio> #include <algorithm> int main() { //freopen("input.txt","r",stdin); const int MAXSIZE=22, dimSize=20; int bacnums…
the 2 version are essentially the same, except version 2 search from the larger end, which reduce the search time in extreme condition from linear to constant, so be faster. version 1 #include <cstdio> #include <algorithm> struct LWPair{ int l…
errors, clauses in place, logical ones, should be avoided. #include <cstdio> #include <cstring> #include <algorithm> int main() { //freopen("input.txt","r",stdin); const int CorNum=201; int ncase, npair, to,from, firs…
errors made, boundary conditions, <= vs < , decreasing vs increasing , ++, –, '0'/'1' vs 0/1 prototype of sum, return the starting position of c-style string containing the sum, just like sprintf return number of characters successfully read. p1=sum…
a problem where OO seems more natural to me, implementing a utility class not instantiable. how to prevent instantiation, thanks to http://stackoverflow.com/questions/10558393/prevent-instantiation-of-an-object-outside-its-factory-method/10558404#105…
(string process, fgets, scanf, neat utilization of switch clause) simple problem, simple code. #include <cstdio> #include <algorithm> #define MAXLEN 22 char password[MAXLEN]; int main() { //freopen("input.txt","r",stdin); i…
Hiking Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 932 Accepted Submission(s): 483 Special Judge Problem Description There are n soda conveniently labeled by 1,2,-,n. beta, their best friend…
Improving the GPA Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 606 Accepted Submission(s): 451 Problem Description Xueba: Using the 4-Point Scale, my GPA is 4.0. In fact, the AVERAGE SCORE of…