有一群人。我们希望制定一个会议日程安排,以便所有人每周都以小组的形式(和一组的)开会。
但是,我不希望同一组中的任何两个人超过一次。
例如,如果我有一组14,我不希望后面的组是14,因为元素32是相同的。
输出应该是一个列表,列表中的每个元素表示给定的一周。然后在每个list元素(week)中,应该有四个三人组和一个两人组的列表,每个人只出现一次,并且在几周之间,不应该有两个人出现在同一个组中。
这个问题有许多可能的解决方案。在所有的组合都用完之前,我们能见面多少周如何在c(A,B,C)中对此进行编码?

最佳答案

elements <- c('A','B','C','D','E','F','G','H','I','J','K','L','M','N')
allcomb <- t(combn(elements, 3)) #Returns 364 different combinations

可以过滤有两个相似字母的字母但是,答案会根据您开始比较的子组而改变。我按顺序做(从A,B,C开始)
for (a in 1:28){
  l <- vector("list", nrow(allcomb))
  for (b in 1:nrow(allcomb)){
    l[[b]] <- sum(allcomb[a,] %in% allcomb[b,])!=2
    }
  allcomb <- allcomb[unlist(l),]
}

经过反复试验得到28分。
> allcomb
      [,1] [,2] [,3]
 [1,] "A"  "B"  "C"
 [2,] "A"  "D"  "E"
 [3,] "A"  "F"  "G"
 [4,] "A"  "H"  "I"
 [5,] "A"  "J"  "K"
 [6,] "A"  "L"  "M"
 [7,] "B"  "D"  "F"
 [8,] "B"  "E"  "G"
 [9,] "B"  "H"  "J"
[10,] "B"  "I"  "K"
[11,] "B"  "L"  "N"
[12,] "C"  "D"  "G"
[13,] "C"  "E"  "F"
[14,] "C"  "H"  "K"
[15,] "C"  "I"  "J"
[16,] "C"  "M"  "N"
[17,] "D"  "H"  "L"
[18,] "D"  "I"  "M"
[19,] "D"  "J"  "N"
[20,] "E"  "H"  "M"
[21,] "E"  "I"  "L"
[22,] "E"  "K"  "N"
[23,] "F"  "H"  "N"
[24,] "F"  "J"  "L"
[25,] "F"  "K"  "M"
[26,] "G"  "I"  "N"
[27,] "G"  "J"  "M"
[28,] "G"  "K"  "L"

关于r - 与元素在同一组中的组合永远不会超过一次,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48909992/

10-12 21:21