- 論壇徽章:
- 0
|
前些天因?yàn)闃I(yè)務(wù)需要寫了一段計(jì)算排列組合的代碼,今天整理了一下,以備后用
array("Student10", "Student11"),
2 => array("Student20", "Student21", "Student22"),
3 => array("Student30"),
4 => array("Student40", "Student41", "Student42", "Student43"));
/* 計(jì)算C(a,1) * C(b, 1) * ... * C(n, 1)的值 */
$CombineCount = 1;
foreach($CombinList as $Key => $Value)
{
$CombineCount *= count($Value);
}
$RepeatTime = $CombineCount;
foreach($CombinList as $ClassNo => $StudentList)
{
// $StudentList中的元素在拆分成組合后縱向出現(xiàn)的最大重復(fù)次數(shù)
$RepeatTime = $RepeatTime / count($StudentList);
$StartPosition = 1;
// 開始對每個(gè)班級的學(xué)生進(jìn)行循環(huán)
foreach($StudentList as $Student)
{
$TempStartPosition = $StartPosition;
$SpaceCount = $CombineCount / count($StudentList) / $RepeatTime;
for($J = 1; $J ";
print_r($Result);
?>
本文來自ChinaUnix博客,如果查看原文請點(diǎn):http://blog.chinaunix.net/u/1777/showart_35855.html |
|