随笔分类 - ACM-动态规划
摘要:Beef McNuggetsHubert ChenFarmer Brown's cows are up in arms, having heard that McDonalds is considering the introduction of a new product: Beef McNuggets. The cows are trying to find any possible way to put such a product in a negative light.One strategy the cows are pursuing is that of `inferio
阅读全文
摘要:Shopping OffersIOI'95In a certain shop, each kind of product has an integer price. For example, the price of a flower is 2 zorkmids (z) and the price of a vase is 5z. In order to attract more customers, the shop introduces some special offers.A special offer consists of one or more product items
阅读全文
摘要:Home on the RangeFarmer John grazes his cows on a large, square field N (2 <= N <= 250) miles on a side (because, for some reason, his cows will only graze on precisely square land segments). Regrettably, the cows have ravaged some of the land (always in 1 mile square increments). FJ needs to
阅读全文
摘要:A GameIOI'96 - Day 1Consider the following two-player game played with a sequence of N positive integers (2 <= N <= 100) laid onto a game board. Player 1 starts the game. The players move alternately by selecting a number from either the left or the right end of the sequence. That number i
阅读全文
摘要:StringsobitsKim SchrijversConsider an ordered set S of strings of N (1 <= N <= 31) bits. Bits, of course, are either 0 or 1.This set of strings is interesting because it is ordered and contains all possible strings of length N that have L (1 <= L <= N) or fewer bits that are `1'.Your
阅读全文
摘要:Cow PedigreesSilviu Ganceanu -- 2003Farmer John is considering purchasing a new herd of cows. In this new herd, each mother cow gives birth to two children. The relationships among the cows can easily be represented by one or more binary trees with a total of N (3 <= N < 200) nodes. The trees
阅读全文
摘要:Dragon BallTime Limit: 3000/1500 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 924Accepted Submission(s): 354Problem DescriptionSean has got a Treasure map which shows when and where the dragon balls will appear. some dragon balls will appear in a line at the same tim
阅读全文
摘要:Human Gene FunctionsTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1338Accepted Submission(s): 767Problem DescriptionIt is well known that a human gene can be considered as a sequence, consisting of four nucleotides, which are simply denoted by fo
阅读全文
摘要:Treasure Hunt IIITime Limit:2 Seconds Memory Limit:65536 KBAlice is exploring the wonderland once again and she finds a strange house. In the house, there arenrooms which form a circle so that each room is connected to its two neighbour room. For exmaple, if Alice is in room 2, then she can go into
阅读全文
摘要:Constructing Roads In JGShining's KingdomTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8812Accepted Submission(s): 2513Problem DescriptionJGShining's kingdom consists of 2n(n is no more than 500,000) small cities which are located in two
阅读全文
摘要:免费馅饼Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 13360Accepted Submission(s): 4410Problem Description都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼。说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉落在他身旁的10米范围内。馅饼如果掉在了地上当然就不能吃了,所以gameboy马上卸下身上的背包去接。但由于小径两侧都不能站人,所以他只能
阅读全文
摘要:To The MaxTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4592Accepted Submission(s): 2165Problem DescriptionGiven a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous sub-array of size 1 x 1 or greater locat
阅读全文
摘要:重温世界杯Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2398Accepted Submission(s): 723Problem Description世界杯结束了,意大利人连本带利的收回了法国人6年前欠他们的债,捧起了大力神杯,成就了4星意大利.世界杯虽然结束了,但是这界世界杯给我们还是留下许多值得回忆的东西.比如我们听到了黄名嘴的3分钟激情解说,我们懂得了原来可以向同一个人出示3张黄牌,我们还看到了齐达内的头不仅能顶球还能顶人…………
阅读全文
摘要:The Tourist Guide Mr. G. works as a tourist guide in Bangladesh. His current assignment is to show a group of tourists a distant city. As in all countries, certain pairs of cities are connected by two-way roads. Each pair of neighboring cities has a bus service that runs only between those two citie
阅读全文
摘要:回文字符串时间限制:3000 ms | 内存限制:65535 KB难度:4描述所谓回文字符串,就是一个字符串,从左到右读和从右到左读是完全一样的,比如"aba"。当然,我们给你的问题不会再简单到判断一个字符串是不是回文字符串。现在要求你,给你一个字符串,可在任意位置添加字符,最少再添加几个字符,可以使这个字符串成为回文字符串。输入第一行给出整数N(0<N<100)接下来的N行,每行一个字符串,每个字符串长度不超过1000.输出每行输出所需添加的最少字符数样例输入1Ab3bd样例输出2分析:d[i][j]表示从第 i 到第 j 的最优解;if(a[i]==a[j]
阅读全文
摘要:括号匹配(二)时间限制:1000 ms | 内存限制:65535 KB难度:6描述给你一个字符串,里面只包含"(",")","[","]"四种符号,请问你需要至少添加多少个括号才能使这些括号匹配起来。如:[]是匹配的([])[]是匹配的((]是不匹配的([)]是不匹配的输入第一行输入一个正整数N,表示测试数据组数(N<=10)每组测试数据都只有一行,是一个字符串S,S中只包含以上所说的四种字符,S的长度不超过100输出对于每组测试数据都输出一个正整数,表示最少需要添加的括号的数量。每组测试输出占一行样例输入4
阅读全文
摘要:最长公共子序列时间限制:3000 ms | 内存限制:65535 KB难度:3描述咱们就不拐弯抹角了,如题,需要你做的就是写一个程序,得出最长公共子序列。tip:最长公共子序列也称作最长公共子串(不要求连续),英文缩写为LCS(Longest Common Subsequence)。其定义是,一个序列 S ,如果分别是两个或多个已知序列的子序列,且是所有符合此条件序列中最长的,则 S 称为已知序列的最长公共子序列。输入第一行给出一个整数N(0<N<100)表示待测数据组数接下来每组数据两行,分别为待测的两组字符串。每个字符串长度不大于1000.输出每组测试数据输出一个整数,表示最长
阅读全文
摘要:The Triangle时间限制:1000 ms | 内存限制:65535 KB难度:4描述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 highest sum of numbers passed on a route that starts at the top and ends somewhere on the base. Each step can go either diagonally down to the left o
阅读全文
摘要:单调递增最长子序列时间限制:3000 ms | 内存限制:65535 KB难度:4描述求一个字符串的最长递增子序列的长度如:dabdbf最长递增子序列就是abdf,长度为4输入第一行一个整数0<n<20,表示有n个字符串要处理随后的n行,每行有一个字符串,该字符串的长度不会超过10000输出输出字符串的最长递增子序列的长度样例输入3aaaababcabklmncdefg样例输出137分析:方法一:求最大字段和的方法相似。O(n^2)dp[i] 以 i 结尾的当然也包括i 在内的最长递增子序列;我经常犯的的一个错误是:dp[i] = d[j] +1(j<i &&
阅读全文
摘要:Max SumTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 72615Accepted Submission(s): 16626Problem DescriptionGiven a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max
阅读全文