Problem 181
コンテンツ
http://projecteuler.net/index.php?section=problems&id=181
import Data.Array (range) import Data.Array.IO (IOArray,newArray,readArray,writeArray) import Control.Monad (forM_) b = 60;w = 40 main = do g <- newArray ((,),(b,w)) :: IO (IOArray (Int,Int) Integer) writeArray g (,) 1 forM_ [(i,j,k,l) | (i,j) <- tail.range $ ((,),(b,w)), (k,l) <- range((i,j),(b,w))] $ (i,j,k,l) -> readArray g ((k-i),(l-j)) >>= t -> readArray g (k,l) >>= writeArray g (k,l).(t+) print =<< readArray g (b,w)
多分javaのほうが可読性が高い。
public class P181{ public static void main(String[] args){ int b = 60, w = 40; long[][] g = new long [b+1][w+1]; for(int i=;i<=b;i++)for(int j=;j<=w;j++){ if(i==&&j==) {g[][]=1;continue;} for(int k=i;k<=b;k++)for(int l=j;l<=w;l++)g[k][l]+=g[k-i][l-j]; } System.out.println(g[b][w]); } }
作成者 Toru Mano
最終更新時刻 2023-01-01 (c70d5a1)