Skip to content

Instantly share code, notes, and snippets.

@ichirin2501
Created August 22, 2012 02:30
Show Gist options
  • Save ichirin2501/3421637 to your computer and use it in GitHub Desktop.
Save ichirin2501/3421637 to your computer and use it in GitHub Desktop.
Project Euler 31
#!/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