由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - phone interview question
相关主题
算法面试题攒人品,yahoo电面面经
问一到题目interview心得:我是如何做到bug free的
问一道题(1)请叫大家一道题
关于n个数的所有和的一个问题请教一道面试题
Facebook Phone Inteview + 流程请教leetcode这题太搞了
面试题总结(2) - Two/Three pointersgoogle面试问题
经典递归题需要搞懂非递归算法吗?问两道微软题
怯生生地问一句。。求助:一道careercup的算法题
相关话题的讨论汇总
话题: dp话题: sum话题: subsets话题: polynomial话题: a1
进入JobHunting版参与讨论
1 (共1页)
b*******e
发帖数: 217
1
give a polynomial complexity algorithm to find whether a set of intergers
can be evenly divided into 3 subsets. that is: if sum of the set is A,
decide whether it can be divided into 3 subsets, each with sum = A/3.
p*****2
发帖数: 21240
2
DFS
f*****e
发帖数: 2992
3
2D dp

【在 b*******e 的大作中提到】
: give a polynomial complexity algorithm to find whether a set of intergers
: can be evenly divided into 3 subsets. that is: if sum of the set is A,
: decide whether it can be divided into 3 subsets, each with sum = A/3.

b*******e
发帖数: 217
4
more details? I can only think of dynamical programming with n * A^3.

【在 p*****2 的大作中提到】
: DFS
p*****2
发帖数: 21240
5

give a polynomial complexity algorithm

【在 f*****e 的大作中提到】
: 2D dp
b*******e
发帖数: 217
6
more details? I can only think a 4-D DP (i, a1, a2, a3)

【在 f*****e 的大作中提到】
: 2D dp
p*****2
发帖数: 21240
7

DFS先找到1/3, 再继续找下一个1/3

【在 b*******e 的大作中提到】
: more details? I can only think a 4-D DP (i, a1, a2, a3)
b*******e
发帖数: 217
8
how to find the first 1/3?

【在 p*****2 的大作中提到】
:
: DFS先找到1/3, 再继续找下一个1/3

f*****e
发帖数: 2992
9
以前讨论过的,tninja给的一个答案。

【在 p*****2 的大作中提到】
:
: DFS先找到1/3, 再继续找下一个1/3

p*****2
发帖数: 21240
10

不好意思。是我理解错了。那就DP吧。

【在 f*****e 的大作中提到】
: 以前讨论过的,tninja给的一个答案。
相关主题
面试题总结(2) - Two/Three pointers攒人品,yahoo电面面经
经典递归题需要搞懂非递归算法吗?interview心得:我是如何做到bug free的
怯生生地问一句。。请叫大家一道题
进入JobHunting版参与讨论
f*****e
发帖数: 2992
11
http://www.mitbbs.com/article_t/JobHunting/32303331.html

【在 f*****e 的大作中提到】
: 以前讨论过的,tninja给的一个答案。
r*********n
发帖数: 4553
12
类似http://people.csail.mit.edu/bdean/6.046/dp/ 里面的第7题balanced partition
假设A是3的倍数,n是数列长度
vector DP[0,1,...,A][0,1,...,n-1]
every time you consider a new integer, fill in one column of DP,the
difference between this problem and the balanced partition problem is that
DP[s][i] is now a vector contains all indices leading to subset sum being
equal to s。
when you back track starting at DP[A/3][n-1], you can easily get all
feasible subsets. Then it's not difficult to determine whether three of them
form the original array.
As such, this may lead to exponential running time when all integers are
equal. To guarantee polynomial time, for each feasible subset, you repeat
the above procedure for the remaining integers that are not in this set.
h***i
发帖数: 1970
13
最多pseudo polynomial,用DP。本身是一个sum of subset问题,NP complete.

【在 b*******e 的大作中提到】
: give a polynomial complexity algorithm to find whether a set of intergers
: can be evenly divided into 3 subsets. that is: if sum of the set is A,
: decide whether it can be divided into 3 subsets, each with sum = A/3.

p*****2
发帖数: 21240
14

them
感觉写起代码来也不容易呀。

【在 r*********n 的大作中提到】
: 类似http://people.csail.mit.edu/bdean/6.046/dp/ 里面的第7题balanced partition
: 假设A是3的倍数,n是数列长度
: vector DP[0,1,...,A][0,1,...,n-1]
: every time you consider a new integer, fill in one column of DP,the
: difference between this problem and the balanced partition problem is that
: DP[s][i] is now a vector contains all indices leading to subset sum being
: equal to s。
: when you back track starting at DP[A/3][n-1], you can easily get all
: feasible subsets. Then it's not difficult to determine whether three of them
: form the original array.

b*****u
发帖数: 648
15
恩,感觉就是leetcode上combination sum的升级版
b*******e
发帖数: 217
16
my solution: 4d np.
recursive function.
Exist(i, a1, a2, a3) = { Exist(i-1, a1-xi, a2, a3) ||
Exist(i-1, a1, a2-xi, a3) ||
Exist(i-1, a1, a2, a3-xi) }
where xi is the ith integer.
a1, a2, a3 are the sum of three subsets in the set.
start from i = 1, a1, a2, a3 = 1
stop at i = n, a1 = a2 = a3 = sum/3.
complexity n * (sum/3)^3.
Any problem with the above DP?
j********x
发帖数: 2330
17
方便透露一下哪家公司的题目么
这题如果不是考察算法基础知识,只能说面试官有意刁难
不要说找到三个,就是找到一个subset sum == A/3都是npc。。。

【在 b*******e 的大作中提到】
: give a polynomial complexity algorithm to find whether a set of intergers
: can be evenly divided into 3 subsets. that is: if sum of the set is A,
: decide whether it can be divided into 3 subsets, each with sum = A/3.

1 (共1页)
进入JobHunting版参与讨论
相关主题
求助:一道careercup的算法题Facebook Phone Inteview + 流程请教
一个面试题面试题总结(2) - Two/Three pointers
k-sum subset problem solution?经典递归题需要搞懂非递归算法吗?
发几个小公司的题目怯生生地问一句。。
算法面试题攒人品,yahoo电面面经
问一到题目interview心得:我是如何做到bug free的
问一道题(1)请叫大家一道题
关于n个数的所有和的一个问题请教一道面试题
相关话题的讨论汇总
话题: dp话题: sum话题: subsets话题: polynomial话题: a1