原帖:http://web.wenxuecity.com/BBSView.php?SubID=computer&MsgID=160243
下面是我写的一个perl程序.这个程序不会直接给出最优解,而是仅仅帮你验证你给出的组合的期望值.有兴趣的朋友可以自己试试:
#!/usr/bin/perl -w
my @arr1 = split(/,/, $ARGV[0]);
my @arr2 = split(/,/, $ARGV[1]);
my $total = 0;
my $testsize = 100000;
for (my $count = 0; $count
shuffle(@arr1);
#print join(',',@arr1),' - ', join(',',@arr2),' => ';
my $sum = 0;
for (my $i=0;$i
$sum += $arr1[$i] * $arr2[$i];
}
#print "sum=$sum\n";
$total += $sum;
}
print 'average=',$total/$testsize;
print "\n";
exit;
sub shuffle {
my $len = @_;
for (my $i = 0; $i
my $b=int(rand($len));
($_[$i],$_[$b])=($_[$b],$_[$i]);
}
}
#### end of program
如何使用:把上面的代码存为一个文本文件:card.pl,然后在命令行输入:
perl card.pl 1,2,3,4,5,6,7 8,9,10,11,12,13
如你所见,程序接受两个参数,分别以逗号分割的两垛牌.你可以自己调节输入你想试的组合.我目前找到的最大可能的期望值是337左右;-)
关于前两天那个最大期望值的问题
所有跟帖:
•
book 11~~~
-奉旨泡妞-
♀
(0 bytes)
()
02/20/2009 postreply
22:59:45
•
不好意思,有个错误要更正一下
-饼干也需要爱啊-
♂
(225 bytes)
()
02/21/2009 postreply
21:45:01
•
好,多谢!你求出的最大期望值对应的大牌是怎么分摊的?
-IIIX-
♂
(0 bytes)
()
02/22/2009 postreply
05:27:05
•
回复:好,多谢!你求出的最大期望值对应的大牌是怎么分摊的?
-饼干也需要爱啊-
♂
(14 bytes)
()
02/22/2009 postreply
19:33:21