Redian新闻
>
包子求Paper on STEM CELL Transl Med
avatar
包子求Paper on STEM CELL Transl Med# Biology - 生物学
F*r
1
找出数组里加起来是sum的几个数。
能想到的就是在生成combination的递归算法基础上,对于每一个产生的combination,
test sum 是否成立,如果是就输出。
请问有更好的方法么?
avatar
z*3
4
Check you link, incomplete link.
avatar
F*r
5
the problem is (subset sum), which is NP complete. So I suppose my solution
wasn't that bad?

【在 g***s 的大作中提到】
: http://en.wikipedia.org/wiki/3SUM
avatar
l*i
6
Thanks for pointing out. I changed it.
avatar
e*e
7
this is a classic DP problem
avatar
g*s
8
连续的才是。这题不是。



【在 e*****e 的大作中提到】
: this is a classic DP problem
avatar
e*e
9
哇~~~不是吧
经典DP啊~~
subset sum....
The array can now be filled in using a simple recursion. Initially, for N ≤
s ≤ P, set
Q(1,s) := (x1 = s).
Then, for i = 2, …, n, set
Q(i,s) := Q(i − 1,s) or (xi = s) or Q(i − 1,s − xi)
for N ≤ s ≤ P.

【在 g***s 的大作中提到】
: 连续的才是。这题不是。
:
: 】

avatar
e*e
10
这和连不连续没有任何关系~~~

【在 g***s 的大作中提到】
: 连续的才是。这题不是。
:
: 】

avatar
g*s
11
"In computer science, the subset sum problem is an important problem in
complexity theory and cryptography. The problem is this: given a set of
integers, does the sum of some non-empty subset equal exactly zero? For
example, given the set { −7, −3, −2, 5, 8}, the answer is
yes because
the subset { −3, −2, 5} sums to zero. The problem is NP-complete.
An equivalent problem is this: given a set of integers and an integer s,
does any non-empty subset sum to s? Subset sum can also be thought of as
a special case of the knapsack problem. One interesting special case of
subset sum is the partition problem, in which s is half of the sum of
all elements in the set."
In the question, it doesn't mention
1) they are integer
2) there are range for the numbers
You solution is just for a special case.

【在 e*****e 的大作中提到】
: 这和连不连续没有任何关系~~~
avatar
F*r
12
能说说具体怎么实现或者怎么reconstruct soluton么?



【在 e*****e 的大作中提到】
: 哇~~~不是吧
: 经典DP啊~~
: subset sum....
: The array can now be filled in using a simple recursion. Initially, for N ≤
: s ≤ P, set
: Q(1,s) := (x1 = s).
: Then, for i = 2, …, n, set
: Q(i,s) := Q(i − 1,s) or (xi = s) or Q(i − 1,s − xi)
: for N ≤ s ≤ P.

avatar
s*y
13
re

【在 e*****e 的大作中提到】
: 这和连不连续没有任何关系~~~
avatar
i*d
14

N ≤

你这个应该算backtracking。

【在 e*****e 的大作中提到】
: 哇~~~不是吧
: 经典DP啊~~
: subset sum....
: The array can now be filled in using a simple recursion. Initially, for N ≤
: s ≤ P, set
: Q(1,s) := (x1 = s).
: Then, for i = 2, …, n, set
: Q(i,s) := Q(i − 1,s) or (xi = s) or Q(i − 1,s − xi)
: for N ≤ s ≤ P.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。