【发布时间】:2012-06-27 15:28:02
【问题描述】:
摘要:
您选择您注册的模块。
每个模块都有多个组。
每个组代表给定模块的讲座。
每个组合应仅包含每个模块中的一个组。
示例:
COS 121 -3 组
COS 132 -2 组
这将为您提供 6 个选项:[1,1],[1,2],[2,1],[2,2],[3,1],[3,2]
我的角度:
我需要使用每个组合来生成时间表,所以我使用一个数组来存储当前正在使用的组和组的总数:arrSubjects[subject,currentGroup,maxGroups]
从逻辑上讲,您应该能够遍历此数组以利用每个组组合。
我只是无法掌握这个解决方案,可能是因为我使用了错误的角度。任何帮助/建议将不胜感激。
我目前的实现: 我对此感到很尴尬,因为这需要很多时间,但它确实有效。 下面是基本的伪代码:
for (all the groups multiplied with eachother) do {
for (all the modules selected) do {
Select a random group between 1 and the nmr of groups
}
}
之后我必须删除所有重复项。
提前致谢
我目前正在处理的代码:
arrPermutations[0,0]:=1;//Current group for 1st module
arrPermutations[0,1]:=3;//Max groups for 1st module
arrPermutations[1,0]:=1;
arrPermutations[1,1]:=3;
arrPermutations[2,0]:=1;//Current group for 3rd module
arrPermutations[2,1]:=3;//Max groups for 3rd module
iCurrent:=iMax; //2
while (arrPermutations[0,0]<=arrPermutations[0,1]) do
begin
//Display arrPermutations
if arrPermutations[iCurrent,0]=arrPermutations[iCurrent,1] then
begin
Inc(arrPermutations[iCurrent-1,0]);
for i := iCurrent to iMax do
arrPermutations[i,0]:=1;
iCurrent:=iMax;
end else
begin
Inc(arrPermutations[iCurrent,0]);
end;
end;
目前我只遍历最后两组。
这是我检查时得到的输出:
============运行1==============
模块,当前组,最大组
1,1,3
2,1,3
3,1,3
============运行2===============
模块,当前组,最大组
1,1,3
2,1,3
3,2,3
============运行3==============
模块,当前组,最大组
1,1,3
2,1,3
3,3,3
============运行 4===============
模块,当前组,最大组
1,1,3
2,2,3
3,1,3
============运行5===============
模块,当前组,最大组
1,1,3
2,2,3
3,2,3
============运行6==============
模块,当前组,最大组
1,1,3
2,2,3
3,3,3
============运行7==============
模块,当前组,最大组
1,1,3
2,3,3
3,1,3
============运行8==============
模块,当前组,最大组
1,1,3
2,3,3
3,2,3
============运行9==============
模块,当前组,最大组
1,1,3
2,3,3
3,3,3
============运行10===============//////这里有问题
模块,当前组,最大组
1,1,3
2,4,3
3,1,3
【问题讨论】:
标签: data-structures permutation combinations