56
Discrete Mathematics Chapter 7 Advanced Counting Techniques 大大大大 大大大大大 大大大 (Lingling Huang)

Discrete Mathematics

  • Upload
    duyen

  • View
    41

  • Download
    0

Embed Size (px)

DESCRIPTION

Discrete Mathematics. Chapter 7 Advanced Counting Techniques. 大葉大學 資訊工程系 黃鈴玲 (Lingling Huang). Outline. 7.1 Recurrence Relations 7.2 Solving Linear Recurrence Relations 7.4 Generating Functions 7.5 Inclusion-Exclusion 7.6 Applications of Inclusion-Exclusion. - PowerPoint PPT Presentation

Citation preview

Page 1: Discrete Mathematics

Discrete Mathematics

Chapter 7 Advanced Counting Techniques

大葉大學 資訊工程系 黃鈴玲 (Lingling Huang)

Page 2: Discrete Mathematics

Outline 7.1 Recurrence Relations 7.2 Solving Linear Recurrence Relations 7.4 Generating Functions 7.5 Inclusion-Exclusion 7.6 Applications of Inclusion-Exclusion

Ch9-2

Page 3: Discrete Mathematics

Ch7-3

7.1 Recurrence Relations( 遞迴關係 )

Example 1. Let {an} be a sequence that satisfies the recurrence relation an=an1an2 for n=2,3,…, and suppose that a0=3,and a1=5.

Here a0=3 and a1=5 are the initial conditions.By the recurrence relation,

a2 = a1a0 = 2

a3 = a2a1 = 3 a4 = a3a2 = 5 :Q1: Applications ?Q2: Are there better ways for computing the terms of

{an}?

Page 4: Discrete Mathematics

Ch7-4

※Modeling with Recurrence RelationsWe can use recurrence relations to model (describe) a wide variety of problems.

Example 3. Compound Interest ( 複利 )Suppose that a person deposits( 存款 ) $10000 in

a saving account at a bank yielding 11% per year with interest compounded annually. How much will be in the account after 30 years ?

Sol : Let Pn denote the amount in the account after n years. Pn=Pn1 + 0.11Pn1=1.11 Pn1,

∴ P30=1.11 P29=(1.11)2 P28=…=(1.11)30 P0

=228922.97

P0=10000

Page 5: Discrete Mathematics

Ch7-5

Example 5. (The Tower of Hanoi)

The rules of the puzzle allow disks to be moved one at a time from one peg to another as long as a disk is never placed on top of a smaller disk. Let Hn denote the number of moves needed to solve the Tower of Hanoi problem with n disks. Set up a recurrence relation for the sequence {Hn}.

Sol : Hn=2Hn-1+1, ( n1 個 disk 先從 peg 1→peg 3, 第 n 個 disk 從 peg 1→peg 2, n1 個 disk 再從 peg 3→peg 2)

peg 1 peg 2 peg 3

H4 moves

目標 : n 個 disk 都從 peg 1 移到 peg 2

H1=1

Page 6: Discrete Mathematics

Ch7-6

上例中 Hn=2Hn1+1, H1=1

∴Hn=2Hn1+1

=2(2Hn2+1)+1

=22Hn2+2+1

=22(2Hn3+1)+2+1

=23Hn3+(22+2+1)

:

=2n1H1+(2n2+2n3+…+1)

=2n1+2n2+…+1

= =2n112

12

n

Page 7: Discrete Mathematics

Ch7-7

Example 6. Find a recurrence relation and give initial conditions for the number of bit strings of length n that do not have two consecutive 0s. How many such bit strings are there of length 5 ?

Sol :

∴ an = an1+an2, n 3 a1=2 (string : 0,1) a2=3 (string : 01,10,11)

∴ a3=a2+a1=5, a4=8, a5=13

1an-1 種

an-2 種 1 0

n-2 n-1 n1 2 n-3…

Let an be the number of bit strings of length n that do not have two consecutive 0s.

Page 8: Discrete Mathematics

Ch7-8

Example 7. (Codeword enumeration)

A computer system considers a string of decimal digits a valid codeword if it contains an even number of 0 digits. Let an be the number of valid n-digit codewords. Find a recurrence relation for an.

Sol :

1~9an1 種

10n1 an1 種 0

∴ an = 9an1 + (10n1an1) = 8an1 + 10n1 , n2 a1 = 9

n-1 n1 2 3 …

Page 9: Discrete Mathematics

Ch7-9

求 an 通解 :

)10108108(8 12323

3 nnn

na

Exercise : 3,23,25,27,29,41 (41 推廣成n)

122

11 10)108(8108

nnn

nnn aaa

)10108(8 122

2 nn

na

)10108108108(8 122321

1 nnnnn ...a

)1081081081088(8 1022321 nnnnnn ...

184102

1 nn

項共有 ,8

10公比為 ,8首項 1 nn-

11

1

84)8

10(848

)18

10(

)1)8

10((8

8

nnnn

nn

n

Page 10: Discrete Mathematics

Ch7-10

7.2 Solving Recurrence RelationsDef 1. A linear homogeneous recurrence relation of

degree k (i.e., k terms) with constant coefficients

is a recurrence relation of the form

where ciR and ck≠0

Example 1 and 2. fn = fn1 + fn2 an = an5

an = an1 + an22

an = nan1

Hn = 2Hn1 + 1

an = c1an1+c2an2+…+ckank

(True, deg=2)(True, deg=5)

(False, not linear)(False , not linear)

(False, not homogeneous)

Page 11: Discrete Mathematics

Ch7-11

Theorem 1.

Let an = c1an1+ c2an2 be a recurrence relation

with c1,c2R.

If r2 c1r c2= 0 ( 稱為 characteristic equation) has two distinct roots r1 and r2.

Then the solution of an is an = 1r1n + 2r2

n ,

for n=0,1,2,…, where 1 , 2 are constants.

(1 , 2 可利用 a0, a1 算出 )

Solving Linear Homogeneous RecurrenceRelations with Constant Coefficients

Page 12: Discrete Mathematics

Ch7-12

Example 3.What’s the solution of the recurrence relation

an = an1 + 2an2

with a0=2 and a1=7 ?Sol :

The characteristic equation is r2 – r 2=0.

Its two roots are r1= 2 and r2 = 1.

Hence an=12n +2 (1)n .

∵a0 = 12 = 2, a1=212=7

∴1 = 3, 2 = 1

an = 32n (1)n.

驗算: a2 = a1 + 2a0 =11 a2= 322 1 =11

r1 與 r2 順序可交換,結果會一樣

Page 13: Discrete Mathematics

Ch7-13

Example 4. Find an explicit formula for the Fibonacci numbers.

Sol :

fn = fn1 + fn2 , n 2, f0=0 , f1=1.

The characteristic equation is r2 r 1=0.

Its two roots are , .

So we have

2

511

r

2

512

r

nnnf )

2

51()

2

51( 21

,0210 f∵ 1)2

51()

2

51( 211

f

5

1 ,

5

121

nnnf )

2

51(

5

1)

2

51(

5

1

Page 14: Discrete Mathematics

Ch7-14

Thm 2.

Let an = c1an1+c2an2 be a recurrence relation

with c1,c2R.

If r2 c1r c2= 0 has only one root r0 .

Then the solution of an is

an = 1 r0n + 2 n r0

n

for n=0,1,2,…, where 1 and 2 are constants.

Page 15: Discrete Mathematics

Ch7-15

Example 5.

What’s the solution of an= 6an1 9an2 with a0=1 and a1=6 ?

Sol :

The root of r2 6r + 9 = 0 is r0 = 3.

Hence an = 1 . 3n +2 . n . 3n .

∵a0 = 1 = 1

a1 = 31 + 32 = 6

∴ 1 = 1 and 2 = 1

an = 3n + n . 3n驗算: a2 = 6a1 9a0 =27

a2= 32 +2 32 =27

Page 16: Discrete Mathematics

Ch7-16

Thm 3.

Let an = c1an1 + c2an2 + … + ckank be a recurrence relation with c1, c2, …, ck R.

If rk c1rk-1 c2rk-2 … ck = 0 has k distinct roots r1, r2,…, rk.

Then the solution of an is

an = 1r1n +2r2

n + …+krkn, for n = 0, 1, 2, …

where 1, 2,…k are constants.

Page 17: Discrete Mathematics

Ch7-17

Example 6 (k = 3)

Find the solution of an = 6an1 11an2 + 6an3

with initial conditions a0=2, a1=5 and a2=15 .Sol :

The roots of r3 6r2 + 11r – 6 = 0 are

r1 = 1, r2 = 2, and r3 = 3

∴an = 1 1n + 2 2n + 3 3n

∵a0 = 1 + 2 + 3 = 2

a1 = 1 + 22 + 33 = 5

a2 = 1 + 42 + 93 = 15

∴an = 1 2n + 2 3n

1 = 1, 2 = 1, 3 = 2

驗算: a3 = 6a2 11a1+ 6a0 =47 a3= 1 23 + 2 33 =47

Page 18: Discrete Mathematics

Ch7-18

Thm 4.

Let an = c1an1 + c2an2 + … + ckank be a recurrence relation with c1, c2, …, ck R.

If rk c1rk1 c2rk2 … ck = 0 has t distinct roots r1, r2, …, rt with multiplicities m1, m2, …, mt respectively, where mi 1,i, and m1+ m2 +…+ mt = k,

then

n

tm

t,mt,t,

nm,m,

nm,m,,n

rnα...nαα...

rnα...nαα

rnα...nααa

t

t

)(

)(

)(

1110

21

12120,2

11

111101

2

2

1

1

where i,j are constants for 1 i t and 0 j mi1.

Page 19: Discrete Mathematics

Ch7-19

補充說明:若特徵方程式的 root 為: 1 (2 重根 ), 2 (3 重根 ), 3 ( 無重根 )

則上述定理給出的通解為:an= (1,1+1,2 n) 1n+ (2,1+2,2 n +2,3 n2) (2)n

+3,1 3n

( 其實變數的的的的的的的的的的的的的的的的的an= (1+2 n) 1n+ (3+4 n +5 n2) (2)n +6 3n

Page 20: Discrete Mathematics

Ch7-20

Example 8. Find the solution to the recurrence relation an = 3an1 3an2 an3 with initial conditionsa0 = 1, a1 = 2 and a2 = 1.

Sol :

r3 + 3r2 + 3r + 1 = 0 has a single root r0 = 1 of multiplicity three.

∴ an = (1+2n+3n2) r0n = (1+2n+3n2)(1)n

∵ a0 = 1 = 1

a1 = (1+2+3) (1) = 2

a2 = 1+22+43 = 1

∴1 = 1, 2 = 3, 3 = 2

an = (1+3n2n2) (1)nExercise : 3,13,15,19

驗算: a3 = 3a2 3a1 a0 =8 a3= (1+33232)(1)3 =8

Page 21: Discrete Mathematics

Ch7-21

Linear Nonhomogeneous RecurrenceRelations with Constant Coefficients

Example: an = 3an1 + 2n

A recurrence relation of the form an = c1an1 + c2an2 + … + ckank + F(n),where c1, c2, …, ck are real numbersand F(n) is a function not identically zero dependingonly on n.

The recurrence relation an = c1an1 + c2an2 + … + ckank

is called the associated homogeneous recurrence relation.

Page 22: Discrete Mathematics

Ch7-22

Example 9: an = an1 + 2n, associated h.r.r an = an1 an = an1 + an2 + n2+1, associated h.r.r an = an1 + an2 an = 3an1 + n3n, associated h.r.r an = 3an1

an = an1 + an3 + n!, associated h.r.r an = an1 + an3

Page 23: Discrete Mathematics

Ch7-23

Theorem 5. If {an (p)} is a particular solution ( 特解 )

of an = c1an1 + c2an2 + … + ckank + F(n),

then every solution is of the form {an (p) + an

(h)}, where {an

(h)} is a solution of

an = c1an1 + c2an2 + … + ckank

Proof. If {an (p)} and {bn} are both solutions of

an = c1an1 + c2an2 + … + ckank + F(n),

then an(p)

= c1an1(p)

+ c2an2 (p)+ … + ckank

(p) + F(n),

and bn = c1bn1 + c2bn2 + … + ckbnk + F(n).

an(p) bn = c1(an1 bn1) + c2(an2 bn2) + …

+ ck(ank bnk)

{an(p) bn} is a solution of an = c1an1 + c2an2 + … + ckank

bn = an(p) + an

(h)

Page 24: Discrete Mathematics

Ch7-24

Example 10. Find all solutions of the recurrence relation an = 3an1 + 2n. What is the solution with a1=3?

Sol :

{associated 的部分 an = 3an1 先解 }

Characteristic equation: r – 3 = 0 r = 3 an(h) = 3n.

{particular solution}

∵ F(n) = 2n Let∴ an(p)

=cn+d, where c, d R.

If an(p)

= cn+d is a solution to an = 3an1 + 2n, then cn+d = 3(c(n1)+d)+2n =3cn 3c d +2n 2cn3c d +2n = (2c+2)n + (d3c) = 0 ( 任何 n 代入都需為 0)

∴2c+2 = 0, and d3c = c = 1, d = 3/2

an(p)

= n 3/2 an = an(h) an

(p) = 3nn 3/2

If a1=31 3/2 = 3 = 11/6

an = (11/6)3nn 3/2

Page 25: Discrete Mathematics

Ch7-25

Example 11. Find all solutions of the recurrence relation an = 5an1 6an2 + 7n.

Sol :

{associated 的部分 an = 5an1 6an2 先解 } Characteristic equation: r2 – 5r + 6 = 0

r1 = 3, r2 = 2

an(h) = 1 3n +2 2n.

{particular solution}

∵ F(n) = 7n Let∴ an(p) = c7n, where c R.

If an(p) = c7n is a solution to an = 5an1 6an2 + 7n,

then c7n = 5c7n16c7n2 + 7n 49c = 35c 6c + 49

c = 49/20 an(p)

= (49/20) 7n

an = an(h) an

(p) = 1 3n +2 2n + (49/20) 7n

Exercise : 23

Page 26: Discrete Mathematics

Ch7-26

Theorem 6.

an = c1an1 + c2an2 + … + ckank + F(n),

where F(n) = (btnt + bt1nt1 +…+ b1n + b0)sn.

When s is not a root of the characteristic equationof the associated linear homogeneous recurrence relation, there is a particular solution of the form

(ptnt + pt1nt1 +…+ p1n + p0)sn.

When s is a root of the characteristic equation and its multiplicity is m, there is a particular solution of the form

nm(ptnt + pt1nt1 +…+ p1n + p0)sn.

Page 27: Discrete Mathematics

Ch7-27

Example 12. What form does a particular solution of the linear nonhomogeneous recurrence relation an = 6an1 9an2 + F(n) have when F(n) =3n, F(n) =n3n,

F(n) =n22n , and F(n) = (n2+1)3n. Sol :

The associated linear homogeneous recurrence relation is an = 6an1 9an2.

characteristic equation: r2 6r 9 = 0 r = 3 (2 重根 )

F(n) =3n, and 3 is a root an(p) = p0n23n

F(n) =n3n, and 3 is a root an(p) = n2(p1n+p0) 3n

F(n) =n22n , and 2 is not a root an(p) = (p2n2+p1n+p0)2n

F(n) = (n2+1)3n , and 3 is a root an

(p) = n2 (p2n2+p1n+p0) 3n Exercise : 27

Page 28: Discrete Mathematics

Ch7-28

Example 13. Find the solutions of the recurrence relation an = an1 + n with a1=1.Sol :

The associated linear homogeneous recurrence relation is an = an1 .

F(n) = n = n(1)n, and 1 is a root an

(p) = n(p1n+p0)1n = p1n2+p0n

將 an(p) 代入 an = an1 + n

p1n2+p0n = p1(n1)2+p0(n1)+n (2p11)n+p0p1=0 p1= ½, p0 p1= ½ an

(p) = (n2+n)/2 an = an

(p) + an(h) = (n2+n)/2+c

characteristic eq.: r 1 = 0 r = 1 an(h) = c(1)n=c

a1=1 c=0 an = an(p) + an

(h) = (n2+n)/2

Exercise : 29

Page 29: Discrete Mathematics

Ch7-29

ex 40: Solve the simultaneous recurrence relations

an = 3an1 + 2bn1

bn = an1 + 2bn1 with a0 = 1 and b0 = 2.

Sol :an bn= 2an1 bn = an2an1

an = 3an1 + 2bn1 = 3an1 + 2an14an2

an = 5an1 4an2 r2 5r 4 = 0 r = 1, 4

an = 1+24n

a0 = 1+2 = 1

a1 = 1+42 = 3a0 + 2b0 = 7 1 = 1, 2 =

an= 4n1 bn = an2an1=4n14n= 4n

Page 30: Discrete Mathematics

Ch7-30

7.4 Generating Functions.

Def 1. The generating function for the sequence a0, a1, a2,… of real numbers is the infinite series

G(x) = a0 + a1x +… + anxn +…

=

( 若數列 {an} 是 finite ,可視為是 infinite ,但後面的項都等於 0)

0k

kk xa

Page 31: Discrete Mathematics

Ch7-31

Example 1. Find the generating functions for the sequences {ak} with

(1) ak= 3

(2) ak = k+1

(3) ak = 2k

(1) G(x) = Sol :

00

3k

k

k

kk xxa

(3) G(x) =

00

)1(k

k

k

kk xkxa(2) G(x) =

00

2k

kk

k

kk xxa

Page 32: Discrete Mathematics

Ch7-32

Example 2. What is the generating function for the sequence 1,1,1,1,1,1 ?

Sol :

1

1

...16

52

x

x

xxx (expansion ,展開式 )

(closed form)

a0 a1 a2 a3 a4 a5 a6及之後都 =0

G(x) = = a0 + a1x + a2x2 + a3x3 +…

0k

kk xa

Exercise : 2

Page 33: Discrete Mathematics

Ch7-33

Example 3.

Let mZ+ and ,for k = 0, 1, …, m.

What is the generating function for the sequence a0, a1,…, am ?

Sol :

G(x) = a0 + a1x + a2x2 + … + amxm

= (1+x)m (by 下面的二項式定理 )

k

mak

mxm

mx

mx

mm

2

210

n

j

jjnnj

nnn

nnn

nnnnn yxyxyyxxyx0

11

110 )()()(...)()()(

Page 34: Discrete Mathematics

Ch7-34

Example 4. The function f (x) = is the generating

function of the sequence 1, 1, 1, …, because

= 1 + x + x2 + …= when |x| < 1.

x1

1

x1

1

0k

kx

Useful Facts About Power Series

Example 5. The function f (x) = is the generating

function of the sequence 1, a, a2, …, because

= 1 + ax + a2x2 + …= when |ax| < 1 for a≠0.

ax1

1

ax1

1

0

)(k

kax

Exercise : 5(a)(b), 11(a)

Page 35: Discrete Mathematics

Ch7-35

Theorem 1.

Let f(x) = and g(x) = .

Then f(x) + g(x) = .

f(x) g(x) = (a0+a1x+a2x2 +…)(b0+b1x +b2x2+…) = (a0b0)+(a0b1+a1b0) x+(a0b2+a1b1+a2b0) x2+… =

0k

kk xa

0k

kk xb

0

)(k

kkk xba

k

k

k

jjkj xba

0 0

Page 36: Discrete Mathematics

Ch7-36

Example 6. Let f (x) = . Use Example 4 to find the

coefficients a0, a1, a2, … in the expansion f (x)= .

21

1

x

0k

kk xa

Sol :

x1

1= 1 + x + x2 + …

21

1

x=

k

k

k

jjkj xba

0 0

00 0

)1(1k

kk

k

k

j

xkx=

ak = k+1

Page 37: Discrete Mathematics

Example 7. Find and

Sol :

Ch7-37

Def 2.

Let uR and kN. Then the extended

binomial coefficient is defined by

k

u

0 if 1

0 if ,!/)1)...(2)(1(

k

kkkuuuuku

321

3

2

4!3/)4)(3)(2(32

16

1!3/)

2

3

2

1

2

1(

321

Page 38: Discrete Mathematics

Ch7-38

Example 8 When the top parameter is a negative integer, the extended binomial coefficient can be expressed in terms of an ordinary binomial coefficient.

!

)1)...(1)((

r

rnnnrn

!

)1)...(1)(()1(

r

rnnnr

)!1(!

)!1()1(

nr

rnr

r

rnr 1)1(

Page 39: Discrete Mathematics

Ch7-39

Thm 2. (The Extended Binomial Theorem)

Let xR with |x|<1 and let uR, then

0

1k

ku xx ku

Page 40: Discrete Mathematics

Ch7-40

Example 9. Find the generating functions for (1+x)n and (1x)n where nZ+

Sol : By the Extended Binomial Theorem,

0

0

0 0

1 )1(

)1( )1( )( !

)1(

)1( )1)(( !

1)1(

k

kk

k

k

k

k

k k

kn

xk

kn

xkn...nnk

xkn...nnk

xk

nx

By replacing x by –x we have

k

k

n xk

knx

1)1(

0

k

kn

k

n k 1)1(:Note

( 跳過 )

Exercise : 11(b)(d)

Page 41: Discrete Mathematics

Ch7-41

Counting Problems and Generating FunctionsGenerating functions can be used to count the number

of combinations of various types.

Example 10.

Find the number of solutions of e1 + e2 + e3 = 17, where e1, e2, e3 are integers with 2 e1 5, 3 e2 6, and 4 e3 7.

Sol : The number of solutions with the indicated constraints is the coefficient of x17 in the expansionof

(x2 + x3 + x4 + x5)(x3 + x4 + x5 + x6)(x4 + x5 + x6 + x7)

( 即相當於找 e1, e2, e3 使 xe1 xe2 xe3 = x17)

(e1, e2, e3)=(4, 6, 7), (5, 5, 7), (5, 6, 6) 共 3 種

Page 42: Discrete Mathematics

Ch7-42

Example 11. In how many different ways can eight identical cookies be distributed among three distinct children if each child receives at least two cookies and no more than four cookies?

Sol : The number of solutions is the coefficient of x8 in the expansion of

(x2 + x3 + x4)3

(c1, c2, c3) = (2, 2, 4), (2, 3, 3), (2, 4, 2), (3, 2, 3), (3, 3, 2), (4, 2, 2) 共 6 種

Exercise: 23

Page 43: Discrete Mathematics

Ch7-43

※Using Generating Functions to solve Recurrence Relations.

Example 16.

Solving the recurrence relation ak = 3ak1 for k=1,2,3,… and initial condition a0 = 2.

Sol :

另法: (by 7.2 節 Thm 1 公式 )

r – 3 = 0 r = 3 an = 3n

∵ a0 = 2 = ∴ an = 2 3n

Page 44: Discrete Mathematics

Ch7-44

Let be the

generating function for {ak}.

First note that ak = 3ak1

G(x) a0 = 3x G(x)

∵a0 = 2 G(x) 3x G(x) = G(x)(13x) = 2

0

2210 ...)(

k

kk xaxaxaaxG

1 1 1 0

111 333

k k k k

kk

kk

kk

kk xaxxaxxaxa

0 0

32)3(231

2)(

k k

kkk xxx

xG

∴ ak = 2 3k

從 k = 1 開始,以避免 ak1 變成 a1

Exercise : 5,7,11,33

Page 45: Discrete Mathematics

Ch7-45

Example 17

Solving ak = 8ak1 +10k1 for k =1,2,3,… and initial condition a1 = 9. (Sec. 7.1 Example 7)

Let

be the generating function for {ak}.

Sol : Let a0 = 1 ( 為計算方便而假設 ).

0

2210 ...)(

k

kk xaxaxaaxG

1

11

1

)108(1)(k

kkk

k

kk xaxaxG

001

1

11 108108

k

kk

k

kk

k

kk

k

kk xxxaxxxa

x

xxxG

101)(8

Page 46: Discrete Mathematics

Ch7-46

x

x

x

xxGx

101

91

1011)()81(

)81

1

101

1(

2

1

)81)(101(

91)(

xxxx

xxG

000

)810(2

1)810(

2

1

k

kkk

k

kk

k

kk xxx

∴ ak = (10k + 8k)/2

Exercise: 33

Page 47: Discrete Mathematics

Ch7-47

7.5 Inclusion-Exclusion 排容原理A,B,C,D : sets

CBACBCABACBACBA.

BABABA.

)2(

)1(

1

1 12

2 23

A

B C

|A|+|B|+|C| 時各部分被計算的次數

?)3( DCBA.

11

1

1

20

+|ABC| 後

-|AB|-|AC|-|BC| 後

Page 48: Discrete Mathematics

Ch7-48

Theorem 1.

A1, A2, …, An : sets

nn

nkjikji

njiji

n

iin

AAAAAA

AAAAAA

...)1(...

...

21,,1

1121

Exercise : 17

Page 49: Discrete Mathematics

Ch7-49

7.6 Applications of Inclusion and Exclusion

Example 1. How many solutions does x1 + x2 + x3 = 11have, where x1, x2, x3 are nonnegative integers withx1 3, x2 4, and x3 6?

Sol :

Let a solution have property P1 if x1 4, property P2 if x2 5, and property P3 if x3 7.

N(P1’P2’P3’) = N N(P1) N(P2) N(P3) + N(P1P2) + N(P2P3) + N(P1P3)N(P1P2P3)

6020

222

424

626

727

11211

Page 50: Discrete Mathematics

Ch7-50

Example 2. How many onto functions are there form set A={1, 2, 3, 4, 5, 6} to set B={a, b, c} ?

Sol : f : A → Bf (1)= {a, b, c}f (2)= ︰ ︰f (6)=

不同的填法造出不同的函數如何使 a,b,c 都出現 ?

The number of onto functions = ( 所有函數個數 ) (a,b,c 中有一個沒被對應 ) + (a,b,c 中二個沒被對應 ) (a,b,c 都沒被對應 )= 63

363

263

16 0123

The Number of Onto Functions

Page 51: Discrete Mathematics

Ch7-51

mn

nn

mnmnmnm nnnn

1)1(

...)3()2(1

11

321

pf : A = {a1, a2, …, am}. B = {b1, b2, …, bn}

f (a1)= f (a2)= ︰ ︰

f (am)=

b1, b2, …, bn

Thm 1. |A| = m , |B| = n

There are

onto functions f : A → B.

Exercise : 8

Page 52: Discrete Mathematics

Ch7-52

Example 3. How many ways are there to assign five different jobs to four different employees if every employee is assigned at least one job?

Sol :Consider the assignment of jobs as a function from the set of five jobs to the set of four employees.

2401234 543

542

541

5

The number of onto functions

Exercise : 9

Page 53: Discrete Mathematics

Ch7-53

Def. A derangement is a permutation of objects that leaves no object in its original position.

Derangements ( 亂序 )

Example 5. The permutation 21453 is a derangement of 12345.But 21543 is not a derangement of 12345.

Page 54: Discrete Mathematics

Ch7-54

D4 = ( 所有 4 個元素的 permutation 數 ) (4 個元素有一個在原位置的 permutation 數 ) + (4 元素中有二個在原位置的 permutation 個數 ) (4 個元素中有三個在原位置的 permutation 個數 ) + (4 元素都在原位置的 permutation 個數 ) = !0

4

4!1

3

4!2

2

4!3

1

4!4

Def. Let Dn be the number of derangements of n objects.

D3 = 2 because the derangements of 123 are 231 and 312.

D2 = 1 because the derangements of 12 are 21.

Page 55: Discrete Mathematics

Ch7-55

Theorem 2. ( 亂序公式 )

Exercise : 13

)!

!0

!0!

! )1(

... !

)!2(

)!2(!2

!

!

)!1(

)!1(!1

! 1( !

!0 )1( ... )!2( )!1( ! 21

nn

n

n

n

n

n

n

n

n

nn

nnnD

n

nn

nnnn

) !

1 )1( ...

!2

1

!1

1 1 ( !

nnD n

n

Proof.

Page 56: Discrete Mathematics

Ch7-56

Exercise 17. How many ways can the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 be arranged so that even digit is in its original position?

Sol :

!5 !6 !7 !8 !9 !1055

45

35

25

15