Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
40
Task/Paraffins/Perl/paraffins.pl
Normal file
40
Task/Paraffins/Perl/paraffins.pl
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
use Math::GMPz;
|
||||
|
||||
my $nmax = 250;
|
||||
my $nbranches = 4;
|
||||
|
||||
my @rooted = map { Math::GMPz->new($_) } 1,1,(0) x $nmax;
|
||||
my @unrooted = map { Math::GMPz->new($_) } 1,1,(0) x $nmax;
|
||||
my @c = map { Math::GMPz->new(0) } 0 .. $nbranches-1;
|
||||
|
||||
sub tree {
|
||||
my($br, $n, $l, $sum, $cnt) = @_;
|
||||
for my $b ($br+1 .. $nbranches) {
|
||||
$sum += $n;
|
||||
return if $sum > $nmax || ($l*2 >= $sum && $b >= $nbranches);
|
||||
if ($b == $br+1) {
|
||||
$c[$br] = $rooted[$n] * $cnt;
|
||||
} else {
|
||||
$c[$br] *= $rooted[$n] + $b - $br - 1;
|
||||
$c[$br] /= $b - $br;
|
||||
}
|
||||
$unrooted[$sum] += $c[$br] if $l*2 < $sum;
|
||||
return if $b >= $nbranches;
|
||||
$rooted[$sum] += $c[$br];
|
||||
for my $m (reverse 1 .. $n-1) {
|
||||
next if $sum+$m > $nmax;
|
||||
tree($b, $m, $l, $sum, $c[$br]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub bicenter {
|
||||
my $s = shift;
|
||||
$unrooted[$s] += $rooted[$s/2] * ($rooted[$s/2]+1) / 2 unless $s & 1;
|
||||
}
|
||||
|
||||
for my $n (1 .. $nmax) {
|
||||
tree(0, $n, $n, 1, Math::GMPz->new(1));
|
||||
bicenter($n);
|
||||
print "$n: $unrooted[$n]\n";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue