UVA 1406 - A Sequence of Numbers
题目链接
题意:给定一些数字,每次操作
C x 表示所有数字加上x
Q x 表示答案加上与2x进行且操作不为0的个数
E 结束,并输出答案
思路:树状数组,首先观察,对于每次查询x而言,只有前x位是是有用的,所以可以开16个树状数组,每个数组表示数字对应前x位下的数字,然后就可以搞了,已经现在加过值为sum,...
分类:
其他好文 时间:
2014-08-16 17:10:20
阅读次数:
227
Given a set of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Thesamerepeated num...
分类:
其他好文 时间:
2014-08-16 17:03:50
阅读次数:
174
Problem Description
Businesses like to have memorable telephone numbers. One way to make a telephone number memorable is to have it spell a memorable word or phrase. For example, you can call the U...
分类:
其他好文 时间:
2014-08-16 16:28:10
阅读次数:
185
Minimum Path SumGiven amxngrid filled with non-negative numbers, find a path from top left to bottom right whichminimizesthe sum of all numbers along ...
分类:
其他好文 时间:
2014-08-16 02:13:49
阅读次数:
189
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the fol...
分类:
其他好文 时间:
2014-08-15 23:47:19
阅读次数:
302
本题需要使用选择矩阵的程序求解,这个和Leetcode上的一个程序是一样道理的。如果使用额外空间,那么是很容易做到的,这里不使用额外空间,直接使用到位操作,空间效率是O(1),这是个非常漂亮的到位旋转程序。
题意还是很重要,这次看错了一句话,就WA了一次:
The maximum amount of cells which contains two equal numbers after ov...
分类:
其他好文 时间:
2014-08-15 22:35:29
阅读次数:
288
普通的求区间连续和的问题,一开始因为是区间移动,但是怕UVA数据太严,直接打表,后来发现自己的担心是多余的。
14044972
1210
Sum of Consecutive Prime Numbers
Accepted
C++
0.049
2014-08-15 10:30:11
打表的话效率可能不是很高.
AC代码:...
分类:
其他好文 时间:
2014-08-15 19:43:29
阅读次数:
182
题意:给定一个字符串,求最少添加多少个字符可使得该字符串变为回文字符串
分析:设原序列S的逆序列为S' ,最少需要补充的字母数 = 原序列S的长度 - S和S'的最长公共子串长度
原因:要求最少添加几个字符,我们可以先从原串中找到一个最长回文串,然后对于原串中不属于这个回文串的字符,在它关于回文串中心的对称位置添加一个相同字符即可。那么需要添加的字符数量即为n-最长回文串长度。
最长回文串可以看作是原串中前面和后面字符的一种匹配(每个后面的字符在前面找到一个符合位置要求的与它相同的字符)。这种的回文匹配和原...
分类:
其他好文 时间:
2014-08-15 18:02:39
阅读次数:
223
题目大意:
给你m个字符,其中有n种字符,每种字符都有两个值,分别是增加一个这样的字符的代价,删除一个这样的字符的代价,让你求将原先给出的那串字符变成回文串的最小代价。
思路分析:
状态方程:dp[i][j] 表示 区间 i-j是回文串的最小代价。
状态转移:
有三种情况。
1、 i+1 ~ j 已经是回文串了,那么对于 i 这个字符,要么删除掉,要么在这个回文串后面加一个 s...
分类:
其他好文 时间:
2014-08-15 17:55:39
阅读次数:
172
Colossal Fibonacci Numbers!
The i'th Fibonacci number f (i) is recursively defined in the following way:
f (0) = 0 and f (1) = 1f (i+2) = f (i+1) + f (i) for every i ≥ 0
Your task is to comput...
分类:
其他好文 时间:
2014-08-15 17:55:09
阅读次数:
241