我必须为问题编写多项式时间算法,如果左边的数字与右边的数字不匹配,应该说接受或拒绝。 您也可以对数字进行分组,示例如下
X& Y ..........& N = SUM
where X, Y, and N can be any integer
Case 1: 4 & 6 & 10 = 14 , accepts
So case 1 accepts because first number and the third number together sum up to 14.
Case 2: 4 & 6 & 10 = 8 rejects
Case 3: 4 & 6 & 10 = 6 , accepts
Case 4: 4 & 6 & 10 = 11 rejects
Some more test cases:
Case 1: 4 & 6 & 10 = 4 , accepts
Case 2: 4 & 6 & 10 = 21 rejects
Case 3: 4 & 6 & 10 = 20 , accepts
Case 4: 4 & 6 & 10 = 17 rejects
Case 5: 4 & 6 & 10 = 16 , accepts
Case 6: 4 & 6 & 10 = 200 rejects
Case 7: 4 & 6 & 10 = 111 , rejects
Case 8: 4 & 6 & 10 = 7 rejects
some more test cases
Case 1 : 1 & 1 & 1 = 3 accepts
Case 2 : 1 & 1 & 1 & 2 & 2 & 22 = 29 accepts
为此我该如何编写多项式时间算法? 这是NP问题吗?
答案 0 :(得分:1)
在我看来,这是子集求和问题,即NP
- 完全(意味着多项式时间解不存在,除非P=NP
)但是{{3}使用动态编程(即数字的时间多项式和总和的值)。