Posted By

cmm7825 on 06/01/10


Tagged


Versions (?)

Problem 67


 / Published in: Perl
 

  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use List::Util qw(max);
  5.  
  6. my @a;
  7.  
  8. open INFILE, "<67.in";
  9.  
  10. while(<INFILE>){
  11. push @a, [ split ];
  12. }
  13.  
  14. my $n = $.;
  15. my $i = 0;
  16. my $value;
  17. my @tmp;
  18. my @sum = ();
  19.  
  20. for (my $r = $n-1; $r >= 0; $r-- ){
  21. @tmp = ();
  22. for my $c (0..$#{$a[$r]}){
  23. if($r == $n-1){
  24. $value = $a[$r][$c];}
  25. else{
  26. $value = $a[$r][$c] + max($sum[$i-1][$c], $sum[$i-1][$c+1]);}
  27. push @tmp, $value;
  28. }
  29. push @sum, [ @tmp ];
  30. $i++;
  31. }
  32.  
  33. print "$value\n";

Report this snippet  

You need to login to post a comment.