更新时间:2023-02-10 07:56:32
设置将七个收入最低的玩家加起来,您将获得28个。这意味着没有薪水高于22的一个人可以在团队中。
Setup Adding up the seven lowest-paid players, you get 28. This means that no one with a salary above 22 can be on the team.
pool <- subset(player_pool,salary<=22)
查找连击从这里开始,我会选择明显的路线而不是寻找效率:
Finding combos From here, I would take the obvious route instead of looking for efficiency:
标识所有行组合
Identify all combos of rows
rs <- combn(seq(nrow(pool)),8)
测试条件
Test conditions
good_rs <- with(pool,apply(rs,2,function(x){
sum(salary[x]) <= 50 &&
length(unique(position[x])) == 5 &&
max(lengths(split(x,team[x]))) <= 3
}))
结果它运行得足够快(不到一秒钟),我看到339个匹配的组合
Results It runs fast enough (under a second), and I see 339 matching combos
length(which(good_rs))
# [1] 339