アルゴリズム

C言語の練習

Cはもうほとんど忘れてしまっているので、復習をかねて昔読んだアルゴリズムの本の問題をやってみようと思った。 bubble sort #include <stdio.h> void swap( int *a, int *b); void bubbleSort( int *a, int length ); void bubbleSort( int *a, int length ) { for(</stdio.h>…

計算量

ビッグオー O(1) < O(log n) < O(n^p) < O(n^x) < O(n!) 用語 用語 読み方 O(n) O of n n! factorial of n 10^n 10 to the n th power

アルゴリズムの問題いろいろ

合計金額になるすべてのお金の組み合わせを計算する。 例:10ドル、5ドル、1ドルを組み合わせて123ドルになるのは何通り? use strict; sub f{ my( $amount, @curs ) = @_; my $cur = shift @curs; my $total; return 0 unless $cur; if( @curs == 0 ) { …