경우의 수: 도로망 길찾기
[문제] 다음 그림과 같이 지점
개를 연결하는 도로망이 있다. 지점
에서 출발하여 지점
를 거쳐 다시 지점
로 도착하는 모든 방법의 수를 구하시오. (단, 출발점과 도착점을 제외하고 지점
는 지나지 않으며, 세 지점
는 두 번 이상 지나지 않는다.)
[해설]
랜덤변수 지정
nab = cm.rn(2,4)
nac = cm.rn(2,5)
nbc = cm.rn(2,5, exc=[nac])
nad = cm.rn(2,4)
nbd = cm.rn(2,4, exc=[nad])
ncd = 1
지정한 변수명으로 변경
#{ 변수명 }# 형태로 입력한다.
수식모드의 경우 $#{ 변수명 }#$
[문제(TeX)]
다음 그림과 같이 지점 $\text{A, B, C, D}$ $4$개를 연결하는 도로망이 있다.
지점 $\text{A}$에서 출발하여 지점 $\text{B}$를 거쳐 다시 지점 $\text{A}$로
도착하는 모든 방법의 수를 구하시오. (단, 출발점과 도착점을 제외하고 지점 $\text{A}$는
지나지 않으며, 세 지점 $\text{B, C, D}$는 두 번 이상 지나지 않는다.)
[해설(TeX)]
1) $\text{A} \rightarrow \text{B} \rightarrow \text{A}$
${nab}\times{nab} = {aba}$
2) $\text{A} \rightarrow \text{B} \rightarrow \text{C}
\rightarrow \text{A} = \text{A} \rightarrow \text{C}
\rightarrow \text{B} \rightarrow \text{A}$
${nab}\times{nbc} \times {nac} = {abca}$
3) $\text{A} \rightarrow \text{B} \rightarrow \text{D}
\rightarrow \text{A} = \text{A} \rightarrow \text{D}
\rightarrow \text{B} \rightarrow \text{A}$
${nab}\times{nbd}\times{nad} = {abda}$
4) $\text{A} \rightarrow \text{B} \rightarrow \text{C}
\rightarrow \text{D}\rightarrow \text{A} = \text{A}
\rightarrow \text{D} \rightarrow \text{C} \rightarrow \text{B}\rightarrow \text{A}$
${nab}\times{nbc}\times{ncd}\times{nad} = {abcda}$
5) $\text{A} \rightarrow \text{B} \rightarrow \text{D}
\rightarrow \text{C}\rightarrow \text{A} = \text{A} \rightarrow \text{C}
\rightarrow \text{D} \rightarrow \text{B}\rightarrow \text{A}$
${nab}\times{nbd}\times{ncd}\times{nac} = {abdca}$
6) $\text{A} \rightarrow \text{C} \rightarrow \text{B}
\rightarrow \text{D}\rightarrow \text{A} = \text{A} \rightarrow \text{D}
\rightarrow \text{B} \rightarrow \text{C}\rightarrow \text{A} $
${nac}\times{nbc}\times{nbd}\times{nad} = {acbda}$
${aba} + 2({abca} + {abda} + {abcda} + {abdca} + {acbda}) = {answer}$
데이터 캔버스: 그림 그리기
변수 정의:
의 좌표 지정
A (0,0) B(10,0) C(c, 2.3) D(d,-1.5)
도형 선택 > 점 > 좌표: A; 점의 반지름: 0.1; text: $\rm A$
도형 선택 > 표시 - 길이 > 선분을 이루는 두 점: A,B; 방향과 깊이: 6; 변환설정(그리기 조건): ab[0]
그리기 조건이 True인 경우에만 보여주고 False인 경우 나타나지 않음
도형 선택 > 표시 - 길이 > AB, AC, BC, BD, CD를 나타내는 선을 위와 같이 반복
기본 수직선 > 축 보이기 체크 해제
문제에 붙여넣기
코드 예시
ab = [False]*4
ac = [False]*5
bc = [False]*5
ad = [False]*4
bd = [False]*4
cd = [True]*1
# number of cases of moving two points
nab = cm.rn(2,4)
nac = cm.rn(2,5)
nbc = cm.rn(2,5, exc=[nac])
nad = cm.rn(2,4)
nbd = cm.rn(2,4, exc=[nad])
ncd = 1
set_ab = random.sample(range(0, 4), nab)
set_ac = random.sample(range(0, 5), nac)
set_bc = random.sample(range(0, 5), nbc)
set_ad = random.sample(range(0, 4), nad)
set_bd = random.sample(range(0, 4), nbd)
for i in set_ab : ab[i] = True
for i in set_ac : ac[i] = True
for i in set_bc : bc[i] = True
for i in set_ad : ad[i] = True
for i in set_bd : bd[i] = True
# number of cases
aba = nab * nab
abca = nab * nbc * nac
abda = nab * nbd * nad
abcda = nab * nbc * ncd * nad
abdca = nab * nbd * ncd * nac
acbda = nac * nbc * nbd * nad
answer = aba + 2*(abca + abda + + abcda + abdca + acbda)
err = cm.rlu([-5,5],exc=[0])
ab_color = ["pink"]*4
ab_th = [2]*4
ac_color = ["pink"]*5
ac_th = [2]*5
bc_color = ["pink"]*5
bc_th = [2]*5
ad_color = ["pink"]*4
ad_th = [2]*4
bd_color = ["pink"]*4
bd_th = [2]*4
cd_color = ["pink"]*1
cd_th = [2]*1
c = cm.rn(3,4)
d = cm.rn(4,6)
cv1 = graphs.DataCanvas.canvas_by_name('cv1')