随笔分类 - 算法_动态规划
摘要:动态规划&矩阵连乘 动态规划的概念 • 与分治方法类似 分-治-合 • 与分治方法不同 子问题之间并非相互独立 • 基本思想 用一个表记录所有子问题的解,不管子问题是否被用到,只要它被计算过,就将其结果备份至表中 动态规划的基本要素 • 最优子结构 利用问题的最优子结构性质,以自底向上的方式递归地从
阅读全文
摘要:Lazy. Lazy. Laaaaaaaaaaaazy!Time Limit:1 SecMemory Limit:128 MBSubmissions:233Solved:78Description YangShenis very lazy. One day, he received a typing task from his leader Mr. He, which is non-technical, time-wasteful and as boring as possible. As this,YangShen, the laziest one in the world, want...
阅读全文
摘要:DollarsNew Zealand currency consists of $100, $50, $20, $10, and $5 notes and $2, $1, 50c, 20c, 10c and 5c coins. Write a program that will determine, for any given amount, in how many ways that amount may be made up. Changing the order of listing does not increase the count. Thus 20c may be made up
阅读全文
摘要:Let Me Count The WaysAfter making a purchase at a large department store, Mel's change was 17 cents. He received 1 dime, 1 nickel, and 2 pennies. Later that day, he was shopping at a convenience store. Again his change was 17 cents. This time he received 2 nickels and 7 pennies. He began to wond
阅读全文
摘要:Coin ChangeSuppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make changes with these coins for a given amount of money.For example, if we have 11 cents, then we can make changes with one 10-cent coin and one 1-cent coin, two 5-cent coins and one 1-cent coi
阅读全文
摘要:Longest Common SubsequenceSequence 1:Sequence 2:Given two sequences of characters, print the length of the longest common subsequence of both sequences. For example, the longest common subsequence of the following two sequences:abcdghaedfhrisadhof length 3.Input consists of pairs of lines. The first
阅读全文
摘要:History GradingBackgroundMany problems in Computer Science involve maximizing some measure according to constraints.Consider a history exam in which students are asked to put several historical events into chronological order. Students who order all the events correctly will receive full credit, but
阅读全文
摘要:Two thievesTime Limit:3 SecMemory Limit:128 MBSubmissions:334Solved:62DescriptionThere are two thieves, both of them have a bag whose capacity is CAP (1<= CAP <= 512). And there are N (N <= 128) diamonds, each of them have a weight w and a value v (1 <= w,v <= 512). The consecutive di
阅读全文
摘要:Counting TrianglesTime Limit:2 Seconds Memory Limit:65536 KBGiven an equilateral triangle with n the length of its side, program to count how many triangles in it.InputThe length n (n 2 int n; 3 int f[501]; 4 void init(){ 5 int i,j; 6 f[0]=0; 7 for(i=1;i<501;i++) 8 f[i]=f[i-1]+i...
阅读全文
摘要:Multiplication PuzzleTime Limit:2 Seconds Memory Limit:65536 KBThe multiplication puzzle is played with a row of cards, each containing a single positive integer. During the move player takes one card out of the row and scores the number of points equal to the product of the number on the card taken
阅读全文
摘要:Largest Rectangle in a HistogramTime Limit:2 Seconds Memory Limit:65536 KBA histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rectangles have equal widths but may have different heights. For example, the figure on the left shows the histogram that consist
阅读全文
摘要:Conquer a New RegionTime Limit:5 Seconds Memory Limit:32768 KBThe wheel of the history rolling forward, our king conquered a new region in a distant continent.There are N towns (numbered from 1 to N) in this region connected by several roads. It's confirmed that there is exact one route between
阅读全文
摘要:Human Gene FunctionsTime Limit:2 Seconds Memory Limit:65536 KBIt 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 identifying human genes and determining their
阅读全文
摘要:Unimodal Palindromic DecompositionsTime Limit:2 Seconds Memory Limit:65536 KBA sequence of positive integers is Palindromic if it reads the same forward and backward. For example:23 11 15 1 37 37 1 15 11 231 1 2 3 4 7 7 10 7 7 4 3 2 1 1A Palindromic sequence is Unimodal Palindromic if the values do
阅读全文
摘要:FatMouse and CheeseTime Limit:10 Seconds Memory Limit:32768 KBFatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension n: each grid location is labelled (p,q) where 0 # includeusing namespace std;int map[105][105];int vis[105][105];int n,k;bool judge(int x,
阅读全文
摘要:Monkey and BananaTime Limit:2 Seconds Memory Limit:65536 KBA group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana at the roof of a building, and at the mean time, provide the monkey with some blocks. If the monkey is clever enough, it shall be able to
阅读全文
摘要:Match for BonusTime Limit:2 Seconds Memory Limit:65536 KBRoy played a game with his roommates the other day.His roommates wrote 2 strings of characters, and gave each character a bonus value. When Roy pinned the positions of one common character in the 2 strings, the bonus value of that character wo
阅读全文
摘要:PalindromesTime Limit: 2 Seconds Memory Limit: 65536 KBA regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDEDCBA" is a palindrome because it is the same when the string is read from left to right as when the string is re
阅读全文