欢迎访问我的个人网站==》 jiashubing.cn
摘要: PieMy birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a numberNof them, of various tastes and of various sizes.Fof my friends are coming to my party and each of them gets a piece of pie. This should be one piece of one pie, not several small pieces since tha 阅读全文
posted @ 2013-07-19 01:23 贾树丙 阅读(549) 评论(0) 推荐(0) 编辑
摘要: A Different TaskThe (Three peg) Tower of Hanoi problem is a popular one in computer science. Briefly the problem is to transfer all the disks from peg-Ato peg-Cusing peg-Bas intermediate one in such a way that at no stage a larger disk is above a smaller disk. Normally, we want the minimum number of 阅读全文
posted @ 2013-07-19 00:55 贾树丙 阅读(576) 评论(0) 推荐(0) 编辑
摘要: Even ParityWe have a grid of sizeNxN. Each cell of the grid initially contains a zero(0) or a one(1).Theparityof a cell is the number of 1s surrounding that cell. A cell is surrounded by at most 4 cells (top, bottom, left, right).Suppose we have a grid of size4x4:1010The parity of each cell would be 阅读全文
posted @ 2013-07-18 21:05 贾树丙 阅读(306) 评论(0) 推荐(0) 编辑
摘要: GraveyardProgramming contests became so popular in the year 2397 that the governor of New Earck -- the largest human-inhabited planet of the galaxy -- opened a special Alley of Contestant Memories (ACM) at the local graveyard. The ACM encircles a green park, and holds the holographic statues of famo 阅读全文
posted @ 2013-07-18 20:45 贾树丙 阅读(354) 评论(0) 推荐(0) 编辑
摘要: Piotr's AntsTime Limit: 2 secondsPiotr likes playing with ants. He hasnof them on a horizontal poleLcm long. Each ant is facing either left or right and walks at a constant speed of 1 cm/s. When two ants bump into each other, they both turn around (instantaneously) and start walking in opposite 阅读全文
posted @ 2013-07-18 15:33 贾树丙 阅读(746) 评论(0) 推荐(0) 编辑
摘要: Spreading the WealthProblemA Communist regime is trying to redistribute wealth in a village. They have have decided to sit everyone around a circular table. First, everyone has converted all of their properties to coins of equal value, such that the total number of coins is divisible by the number o 阅读全文
posted @ 2013-07-18 15:11 贾树丙 阅读(718) 评论(0) 推荐(0) 编辑
摘要: Exploring PyramidsArchaeologists have discovered a new set of hidden caves in one of the Egyptian pyramids. The decryption of ancient hieroglyphs on the walls nearby showed that the caves structure is as follows. There arencaves in a pyramid, connected by narrow passages, one of the caves is connect 阅读全文
posted @ 2013-07-18 14:04 贾树丙 阅读(301) 评论(0) 推荐(0) 编辑
摘要: Commando WarThere is a war and it doesn't look very promising for your country. Now it's time to act. You have a commando squad at your disposal and planning an ambush on an important enemy camp located nearby. You haveNsoldiers in your squad. In your master-plan, every single soldier has a 阅读全文
posted @ 2013-07-16 18:54 贾树丙 阅读(484) 评论(1) 推荐(0) 编辑
摘要: Problem BThe Twin TowersInput:standard inputOutput:standard outputOnce upon a time, in an ancient Empire, there were two towers of dissimilar shapes in two different cities. The towers were built by putting circular tiles one upon another. Each of the tiles was of the same height and had integral ra 阅读全文
posted @ 2013-07-11 08:47 贾树丙 阅读(350) 评论(0) 推荐(0) 编辑
摘要: 打印路径时需要引进一个数组b进行递归打印在LCS中,如果是公共子节点,则标记为1,如果不是,标记为2、3,分别表示往上递归或者往左递归对于样例:/*输入ABCBDABBDCABA*/数组c中各值为: 数组b中各值为: # include# include# define maxn 105# define max(a,b) a>b?a:bint c[maxn][maxn],b[maxn][maxn],m,n;char x[maxn],y[maxn];void lcs(int i,int j){ if ... 阅读全文
posted @ 2013-07-10 20:30 贾树丙 阅读(982) 评论(0) 推荐(0) 编辑
摘要: 全排列 •从n个不同元素中任取m(m≤n)个元素,按照一定的顺序排列起来,叫做从n各不同元素中取出m个元素的一个排列。当m=n时所有的排列情况叫全排列。 •设一组数R={r1,r2,r3,...,rn},全排列为perm(R)。 n=1时,Perm(R)=r,其中r是集合中唯一元素 n>1时,Per 阅读全文
posted @ 2013-06-24 09:54 贾树丙 阅读(338) 评论(0) 推荐(0) 编辑
摘要: N皇后问题 •问题描述 在n×n格的棋盘上放置彼此不受攻击的n个皇后。按照国际象棋的规则,皇后可以攻击与之处在同一行或同一列或同一斜线上的棋子。n后问题等价于再n×n的棋盘上放置n个皇后,任何2个皇后不妨在同一行或同一列或同一斜线上。 •算法分析 只考虑第i个皇后放置在第i行的哪一列,所以在放置第i 阅读全文
posted @ 2013-06-23 12:49 贾树丙 阅读(692) 评论(0) 推荐(0) 编辑
摘要: 哈夫曼编码 • 编码 普通的编码都是定长的,比如常用的ASCII编码,每个字符都是8个bit • 变长编码 变长编码比固定编码好一些,即对频率高的字符赋以短编码,对频率低的字符赋以长编码。 a b c d e f 频率 45 13 12 16 9 5 固定 000 001 010 011 100 1 阅读全文
posted @ 2013-06-22 14:03 贾树丙 阅读(793) 评论(0) 推荐(0) 编辑
摘要: 0-1背包 • 给定n种物品和一背包,物品i的重量是wi,其价值是pi,背包的容量是M,问如何选择装入背包中的物品总价值最大? 背包的背负有上限,因此在这个上限内尽可能多的装东西,并且价值越多越好 • 0-1背包问题的解决办法 穷举算法 动态规划算法 贪心算法(未必获得最优解) 回溯算法 •动态规划 阅读全文
posted @ 2013-06-22 13:47 贾树丙 阅读(393) 评论(0) 推荐(0) 编辑
摘要: 最大连续子段和 • 给定长度为n的整数序列,a[1...n], 求[1,n]某个子区间[i,j]使得a[i]+…+a[j]和最大,或者求出最大的这个和。例如(-2,11,-4,13,-5,2)的最大子段和为20,所求子区间为[2,4]。 • 穷举法(3次for循环) 第1次for循环,遍历数组所有数 阅读全文
posted @ 2013-06-22 13:27 贾树丙 阅读(1051) 评论(0) 推荐(0) 编辑