且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

确定O(n)中子集序列的算法?

更新时间:2023-11-20 20:11:46

我并不完全相信此处需要进行归纳。

I'm not entirely convinced that induction is necessary here.

这是我的两分钱:

假设您有一个数字 S 和整数 k 的序列,并且您已经知道存在一个子集总和为 k 的数字。现在,从序列中删除一个数字(称为 i ),然后在剩余的内容上使用黑框(使用相同的 k 像以前一样。)

Suppose you have a sequence of numbers S, and integer k, and you already know that there exists a subset of numbers whose sum is k. Now, remove a number from your sequence (call it i), and use your black box on what remains (using the same k as before).


  • 如果算法在新序列上返回是,那么对 i S 的任何子集,其总和为 k

  • 如果算法在新序列上返回否,那么这将告诉您有关 i S $的任何子集的信息c $ c>的总和为 k

  • If the algorithm returns YES on the new sequence, what does that tell you about i and any subset of S whose sum is k?
  • If the algorithm returns NO on the new sequence, what does that tell you about i and any subset of S whose sum is k?