All pastes #776435 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-11-16 01:44 UTC
rendered paste body
my $n = 100;
my @c = (1,5,10,25,50);
my @r;

for (my $k=0;$k<=$n;$k++) {
    my @v;
    my $t = ($k==0)?1:0;
    for (my $i=0;$i<@c;$i++) {
	$t += $r[$k-$c[$i]][$i] if ($k-$c[$i])>=0;
	$v[$i] = $t;
    }
    push @r, \@v;
}
print $r[$n][$#c]," ways to write $n as sums of: @c\n";