algorithm - Anagram 生成器 - 这不是一种子集和吗?

标签 algorithm language-agnostic subset-sum

字谜:

An anagram is a type of word play, the result of rearranging the letters of a word or phrase to produce a new word or phrase, using all the original letters exactly once;

子集和问题:

The problem is this: given a set of integers, is there a non-empty subset whose sum is 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.

现在假设我们有一个包含 n 个单词的字典。现在 Anagram Generation 问题可以表述为在字典中找到一组单词(n 个单词),这些单词用完了输入的所有字母。那么它不就变成了一种子集和问题吗。

我错了吗?

最佳答案

两个问题类似但不是isomorphic .

  • 在变位词中,字母的顺序很重要。在子集总和中,顺序无关紧要。
  • 在变位词中,必须使用所有字母。在子集和中,任何子集都可以。
  • 在一个变位词中,子组必须形成从一个相对较小的允许单词字典(字典)中提取的单词。在子集总和中,组不受限制(没有允许分组的字典)。

关于algorithm - Anagram 生成器 - 这不是一种子集和吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8707821/

相关文章:

java - 有人能给我解释一下这个排列/紊乱程序吗

algorithm - 打印总和等于 k ​​的集合的子集

algorithm - 如果子问题 [0/1 knapsack] 没有重叠,DP 如何提供帮助

检查线性和为零的算法

float 子集和问题的递归函数

algorithm - 查找包含指定集合中每个字符的最短单词组合

math - 计算到路径的距离

algorithm - 世界需要一种算法来在二维正方形中找到总和相同的数字

algorithm - 寻找分区问题算法返回 true 的最大值子集

language-agnostic - 这个图案有名字吗?