Created
August 22, 2012 02:30
-
-
Save ichirin2501/3421637 to your computer and use it in GitHub Desktop.
Project Euler 31
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Data::Dumper; | |
sub calc{ | |
my $L = shift; | |
my @coin = $#_ == 0 ? @{$_[0]} : @_; | |
my @dp = (0) x ($L + 1); | |
$dp[0] = 1; | |
foreach my $c (@coin){ | |
for(my $i=$c; $i<=$L; $i++){ | |
$dp[$i] += $dp[$i - $c]; | |
} | |
} | |
return $dp[$L]; | |
} | |
print calc(200,[1,2,5,10,20,50,100,200]), "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment