boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 问一道面试题目
相关主题
请教一道算法题
Google电话面试题目
Given an array of N integers from range [0, N] and one is missing. Find the missing number.
请教一个数论的问题
请教一道题目
问一个面试题
Given an int array and an int value. Find all pairs in arr
这个怎么弄?
问一道老题
请教一个题目
相关话题的讨论汇总
话题: array话题: given话题: adjustment话题: integer话题: greater
进入JobHunting版参与讨论
1 (共1页)
l******2
发帖数: 41
1
Given an integer array, adjust each integers so that the difference of every
adjcent integers are not greater than a given number target.
If the array before adjustment is A, the array after adjustment is B, you
should minimize the sum of |A[i]-B[i]|
You can assume each number in the array is a positive integer and not
greater than 100
Given [1,4,2,3] and target=1, one of the solutions is [2,3,2,3], the
adjustment cost is 2 and it's minimal. Return 2.
r****7
发帖数: 2282
2
这个不就动态规划么,O(n)的复杂度

every

【在 l******2 的大作中提到】
: Given an integer array, adjust each integers so that the difference of every
: adjcent integers are not greater than a given number target.
: If the array before adjustment is A, the array after adjustment is B, you
: should minimize the sum of |A[i]-B[i]|
: You can assume each number in the array is a positive integer and not
: greater than 100
: Given [1,4,2,3] and target=1, one of the solutions is [2,3,2,3], the
: adjustment cost is 2 and it's minimal. Return 2.

i*********e
发帖数: 21
3
element value需要在合理范围内,否则没法dp。
楼主应该漏了这点。
m***l
发帖数: 1
4
"You can assume each number in the array is a positive integer and not
greater than 100 "
所以可以DP.
另一个方法是. 表明这个问题可以写成min-cost flow. 然后这个图很特别, 是series-
parallel graph.
然后表明用Booth&Tarjan的算法O(n log n)的时间即可.
t******5
发帖数: 30
5
能具体说说算法么,谢谢

【在 r****7 的大作中提到】
: 这个不就动态规划么,O(n)的复杂度
:
: every

b*********e
发帖数: 26
6
int f[n][100]
第一维是数组里的数,第二维是那个数的取值,f[i][j]是第i个数取j(0 的cost
转移方程很恶心如果k很大的话
如果k==1的话
f[i][j]=min(f[i-1][j-1],f[i-1][j],f[i-1][j+1])+ |A[i]-j|
最后输出f[N-1][]里最小的元素即可

【在 t******5 的大作中提到】
: 能具体说说算法么,谢谢
b*********e
发帖数: 26
7
直接求max(A)和min(A)就好了吧

【在 i*********e 的大作中提到】
: element value需要在合理范围内,否则没法dp。
: 楼主应该漏了这点。

1 (共1页)
进入JobHunting版参与讨论
相关主题
请教一个题目
请教一道L的题
求问一个题
彭博 面试题
问一道题
Search in a sorted, rotated list
求教一道DP的面试题,minimum adjustment cost
[合集] Google电话面试题目
一道面试算法题
算法作业求教
相关话题的讨论汇总
话题: array话题: given话题: adjustment话题: integer话题: greater