LoginSignup
0
1

More than 5 years have passed since last update.

Color > 4色の合成 > 組合せ数は

Last updated at Posted at 2017-03-28
動作環境
C++ Builder XE4

4つの色がある。
それらの色の合成の組合せ総数はいくつか。

使う式は以下のC (Combination)。

{}_nC_r = \frac{n!}{(n-r)!r!}

1色だけ

{}_4C_1 = \frac{4!}{(4-1)!1!} = 4

2色

{}_4C_2 = \frac{4!}{(4-2)!2!} = \frac{4*3*2*1}{2*1*2*1} = 6

3色

1色と同じになり4

4色

{}_4C_4 = \frac{4!}{(4-4)!4!} = 1

合計

4 + 6 + 4 + 1 = 15

0色という場合もあるとすると16パターン。

実装

http://stackoverflow.com/questions/12991758/creating-all-possible-k-combinations-of-n-items-in-c
に実装例がある。
組合せ数ではなく、実際の組合せを表示する。

dorserg氏による実装例を使った結果が以下。(n=4, r=2)
http://ideone.com/ongVuG

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1