Basic Principles
Multiplication Principle
- If an activity can be constructed in successive steps and
- step 1 can be done in ways,
- step 2 can be done in ways,
- step can be done in ways,
- then the number of different possible activities is
Sometimes, Multiplication Principle, followed by “subtraction” x ทั้งหมด ลบ ตรงข้าม?
- อาจจะมีถามเรื่อง Subset 03 Sets, Relations, and Functions
Addition Principle
- Used when the arrangements under consideration can be divided into “disjoint cases”.
- หากการทำงานให้เสร็จมีหลายแบบ ให้แยกคิดแต่ละวิธีด้วยการคูณ (ทำงานให้เสร็จซะก่อน)
แล้วจึงนำมาบวก กัน เป็นวิธีทั้งหมดที่ทำได้- The number of all arrangement:
ระวังโจทย์ที่เป็นมันสามารถมีบางตัวซ้ำกันได้ อย่าลืมลบออกด้วย อย่านับซ้ำ!


- เหมือนโจทย์ปัญหา จำนวนสมาชิกใน Set แบบนั้นเลย!
Permutation and Combination
Permutation
- Definition: A permutation of distinct elements is an ordering of the elements
Linear
Theorem: There are permutations of elements.
- จริง ๆ นิยามของ ก็มาจาก กฎการคูณนั่นแหละ!
Circular

- “Fixed ไว้ 1 จุด” แล้วที่เหลือคิดเหมือนเส้นตรง
- 2D
- ถ้ามีของแตกต่างกัน สิ่ง นำมาจัดเรียงสับเปลี่ยนแบบวงกลม ได้
In general: There are ways that persons can be seated around a circular table.
-Permutation
(ไม่ได้ใช้บ่อยขนาดนั้น)
- การหาจำนวนวิธีเรียงสับเปลี่ยนของ สิ่ง (แตกต่างกันทั้งหมด) โดยการนำมาจัดครั้งละ สิ่ง
- ลำดับมีความสำคัญ
- เลือกมาก่อนแล้วจัดเรียงสลับ ๆ
-Combination
- เลือก
- ลำดับไม่มีความสำคัญ
Generalized Permutations and Combinations
- In this section we consider
- Orderings of sequences containing repetitions
- Unordered selections in which repetitions are allowed
Generalized Permutation
- Suppose that a sequence of items has identical objects of type 1, identical objects of type 2, , and identical objects of type . Then the number of orderings of is
- เจอของซ้ำ
Generalized Combination
| No Repetitions | Repetitions Allowed | |
|---|---|---|
| Ordered Selections (Fixed Order) | ||
| Unordered Selections | Stars & Bar |
Stars and Bars
Distribute identical objects among a number of different recipients
- เวลาที่จะ Solve คำถามแนว แบบนี้นะ
- กรณีไม่มี Constraint อะไร
- ให้ใช้ Stars & Bars ปกติ
- แต่ถ้ามี Constraint แค่ช่วงล่าง เช่น
- Constraint มีความหมายเหมือนกัน (แต่ถ้าเลขอื่นต้องระวังนะ)
- หากมี Constraint เช่น
- Constraint ให้เปลี่ยนสมการให้ดูง่ายกว่าเดิม แบบนี้
- Constraint ถ้าเป็นแบบนี้เปลี่ยนเป็น
- ถ้ามี Constraint ช่วงบนด้วย
- จัดการ ช่วงล่าง ให้เรียบร้อยก่อน แล้วค่อยหาคำตอบสมการ— แล้วค่อยเอามาลบกับช่วงที่มีช่วงบนร่วมอยู่ด้วย
- การจะเปลี่ยนสมการช่วงบนจะดูยากนิดนึงนะ แต่มองได้แน่นอน
- ถ้าเป็นแบบนี้ก็ต้องเอาช่วงบนเป็น ก็คือเราไม่เอา 7 ขึ้นไปถูกมั้ย (มองให้ออก ไม่รู้จะเขียนไง555)
- กรณีไม่มี Constraint อะไร
วิธีนี้เหมือนจะไม่ถูกต้อง 100% นะ! ทำตามวิธีครูจะแม่นกว่า!
Stars & Bars for Nested Loop
\begin{algorithm}
\caption{How many times is the statement $x := x + 1$ executed?}
\begin{algorithmic}
\For{$i := 1$ \to $5$}
\For{$j := 1$ \to $i$}
\State $x:= x+1$
\EndFor
\EndFor
\end{algorithmic}
\end{algorithm} 
- หลังกำแพงเวลาคิดก็จะได้ เลยไง! ก็ถือว่าเป็นคำตอบของข้อนี้โลดดด
\begin{algorithm}
\caption{How many times is the statement $x := x + 1$ executed?}
\begin{algorithmic}
\For{$i := 1$ \to $10$}
\For{$j := 1$ \to $i$}
\For{$k := 1$ \to $j$}
\State $x:= x+1$
\EndFor
\EndFor
\EndFor
\end{algorithmic}
\end{algorithm} 
- หลังกำแพงจะได้ ก็เป็นคำตอบของข้อนี้เลยทันที~~~
\begin{algorithm}
\caption{How many times is the statement $x := x + 1$ executed?}
\begin{algorithmic}
\For{$i := 3$ \to $10$}
\For{$j := 3$ \to $i$}
\For{$k := 3$ \to $j$}
\State $x:= x+1$
\EndFor
\EndFor
\EndFor
\end{algorithmic}
\end{algorithm} 