np-complete

Algorithm to Divide a list of numbers into 2 equal sum lists

為{幸葍}努か 提交于 2019-11-27 11:08:44
There is a list of numbers. The list is to be divided into 2 equal sized lists, with a minimal difference in sum. The sums have to be printed. #Example: >>>que = [2,3,10,5,8,9,7,3,5,2] >>>make_teams(que) 27 27 Is there an error in the following code algorithm for some case? How do I optimize and/or pythonize this? def make_teams(que): que.sort() if len(que)%2: que.insert(0,0) t1,t2 = [],[] while que: val = (que.pop(), que.pop()) if sum(t1)>sum(t2): t2.append(val[0]) t1.append(val[1]) else: t1.append(val[0]) t2.append(val[1]) print min(sum(t1),sum(t2)), max(sum(t1),sum(t2)), "\n" Question is

What's “P=NP?”, and why is it such a famous question? [closed]

家住魔仙堡 提交于 2019-11-27 04:54:52
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 7 years ago . The question of whether P=NP is perhaps the most famous in all of Computer Science. What does it mean? And why is it so interesting? Oh, and for extra credit, please post a proof of the statement's truth or falsehood. :) 回答1: P stands for polynomial time. NP stands for non-deterministic polynomial time.

Algorithm to find which numbers from a list of size n sum to another number

时光怂恿深爱的人放手 提交于 2019-11-26 17:43:55
I have a decimal number (let's call it goal ) and an array of other decimal numbers (let's call the array elements ) and I need to find all the combinations of numbers from elements which sum to goal. I have a preference for a solution in C# (.Net 2.0) but may the best algorithm win irrespective. Your method signature might look something like: public decimal[][] Solve(decimal goal, decimal[] elements) Sam Meldrum Interesting answers. Thank you for the pointers to Wikipedia - whilst interesting - they don't actually solve the problem as stated as I was looking for exact matches - more of an

Algorithm to Divide a list of numbers into 2 equal sum lists

雨燕双飞 提交于 2019-11-26 15:26:21
问题 There is a list of numbers. The list is to be divided into 2 equal sized lists, with a minimal difference in sum. The sums have to be printed. #Example: >>>que = [2,3,10,5,8,9,7,3,5,2] >>>make_teams(que) 27 27 Is there an error in the following code algorithm for some case? How do I optimize and/or pythonize this? def make_teams(que): que.sort() if len(que)%2: que.insert(0,0) t1,t2 = [],[] while que: val = (que.pop(), que.pop()) if sum(t1)>sum(t2): t2.append(val[0]) t1.append(val[1]) else: t1

Algorithm to find which numbers from a list of size n sum to another number

依然范特西╮ 提交于 2019-11-26 06:06:59
问题 I have a decimal number (let\'s call it goal ) and an array of other decimal numbers (let\'s call the array elements ) and I need to find all the combinations of numbers from elements which sum to goal. I have a preference for a solution in C# (.Net 2.0) but may the best algorithm win irrespective. Your method signature might look something like: public decimal[][] Solve(decimal goal, decimal[] elements) 回答1: Interesting answers. Thank you for the pointers to Wikipedia - whilst interesting -

What are the differences between NP, NP-Complete and NP-Hard?

倖福魔咒の 提交于 2019-11-26 02:18:31
What are the differences between NP , NP-Complete and NP-Hard ? I am aware of many resources all over the web. I'd like to read your explanations, and the reason is they might be different from what's out there, or there is something that I'm not aware of. jason I assume that you are looking for intuitive definitions, since the technical definitions require quite some time to understand. First of all, let's remember a preliminary needed concept to understand those definitions. Decision problem : A problem with a yes or no answer. Now, let us define those complexity classes . P P is a

What are the differences between NP, NP-Complete and NP-Hard?

纵饮孤独 提交于 2019-11-26 01:50:03
问题 What are the differences between NP , NP-Complete and NP-Hard ? I am aware of many resources all over the web. I\'d like to read your explanations, and the reason is they might be different from what\'s out there, or there is something that I\'m not aware of. 回答1: I assume that you are looking for intuitive definitions, since the technical definitions require quite some time to understand. First of all, let's remember a preliminary needed concept to understand those definitions. Decision