<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://tcs.nju.edu.cn/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=0%3A0%3A0%3A0%3A0%3A0%3A0%3A1</id>
	<title>TCS Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://tcs.nju.edu.cn/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=0%3A0%3A0%3A0%3A0%3A0%3A0%3A1"/>
	<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Special:Contributions/0:0:0:0:0:0:0:1"/>
	<updated>2026-04-30T17:12:37Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Basic_enumeration&amp;diff=2891</id>
		<title>Combinatorics (Fall 2010)/Basic enumeration</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Basic_enumeration&amp;diff=2891"/>
		<updated>2010-07-10T07:19:06Z</updated>

		<summary type="html">&lt;p&gt;0:0:0:0:0:0:0:1: /* Subsets */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Counting Problems ==&lt;br /&gt;
&lt;br /&gt;
== Sets and Multisets ==&lt;br /&gt;
=== Subsets ===&lt;br /&gt;
We want to count the number of subsets of a set.&lt;br /&gt;
&lt;br /&gt;
Let&amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set, or &#039;&#039;&#039;&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set&#039;&#039;&#039; for short. &lt;br /&gt;
Let &amp;lt;math&amp;gt;2^S=\{T\mid T\subset S\}&amp;lt;/math&amp;gt; denote the set of all subset of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;. &amp;lt;math&amp;gt;2^S&amp;lt;/math&amp;gt; is called the &#039;&#039;&#039;power set&#039;&#039;&#039; of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We give a combinatorial proof that &amp;lt;math&amp;gt;|2^S|=2^n&amp;lt;/math&amp;gt;. We observe that every subset &amp;lt;math&amp;gt;T\in 2^S&amp;lt;/math&amp;gt; corresponds to a unique bit-vector &amp;lt;math&amp;gt;v\in\{0,1\}^S&amp;lt;/math&amp;gt;, such that each bit &amp;lt;math&amp;gt;v_i&amp;lt;/math&amp;gt; indicates whether &amp;lt;math&amp;gt;x_i\in S&amp;lt;/math&amp;gt;. Formally, define a map &amp;lt;math&amp;gt;\phi:2^S\rightarrow\{0,1\}^n&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;\phi(T)=(v_1,v_2,\ldots,v_n)&amp;lt;/math&amp;gt;, where&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
v_i=\begin{cases}&lt;br /&gt;
1 &amp;amp; \mbox{if }x_i\in T\\&lt;br /&gt;
0 &amp;amp; \mbox{if }x_i\not\in T.&lt;br /&gt;
\end{cases}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The map &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; is a &#039;&#039;&#039;bijection&#039;&#039;&#039; (a 1-1 correspondence). The proof that &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; is a bijection is left as an exercise.&lt;br /&gt;
&lt;br /&gt;
Since there is a bijection between &amp;lt;math&amp;gt;2^S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\{0,1\}^n&amp;lt;/math&amp;gt;, it holds that &amp;lt;math&amp;gt;|2^S|=|\{0,1\}^n|=2^n\,&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Here we apply &#039;&#039;&amp;quot;the rule of bijection&amp;quot;&#039;&#039;.&lt;br /&gt;
*&#039;&#039;&#039;The rule of bijection&#039;&#039;&#039;: if there exists a bijection between finite sets &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;, then &amp;lt;math&amp;gt;|P|=|Q|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we know that &amp;lt;math&amp;gt;|\{0,1\}^n|=2^n\,&amp;lt;/math&amp;gt;? We use &#039;&#039;&amp;quot;the rule of product&amp;quot;&#039;&#039;.&lt;br /&gt;
*&#039;&#039;&#039;The rule of product&#039;&#039;&#039;: for any finite sets &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;, the cardinality of the Cartesian product &amp;lt;math&amp;gt;|P\times Q|=|P|\cdot|Q|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To count the size of &amp;lt;math&amp;gt;\{0,1\}^n\,&amp;lt;/math&amp;gt;, we write &amp;lt;math&amp;gt;\{0,1\}^n=\{0,1\}\times\{0,1\}^{n-1}&amp;lt;/math&amp;gt;, thus &amp;lt;math&amp;gt;|\{0,1\}^n|=2|\{0,1\}^{n-1}|\,&amp;lt;/math&amp;gt;. Solving the recursion, we have that &amp;lt;math&amp;gt;|\{0,1\}^n|=2^n\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are two elements of the proof:&lt;br /&gt;
* Find a 1-1 correspondence between subsets of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set and &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-bit vectors.&lt;br /&gt;
: An application of this in Computer Science is that we can use bit-array as a data structure for sets: any set defined over a &#039;&#039;&#039;universe&#039;&#039;&#039; &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; can be represented by an array of &amp;lt;math&amp;gt;|U|&amp;lt;/math&amp;gt; bits.&lt;br /&gt;
* The rule of bijection: if there is a 1-1 correspondence between two sets, then their cardinalities are the same.&lt;br /&gt;
&lt;br /&gt;
Many counting problems are solved by establishing a bijection between the set to be counted and some easy-to-count set. This kind of proofs are usually called (non-rigorously) &#039;&#039;&#039;combinatorial proofs&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
We give an alternative proof that &amp;lt;math&amp;gt;|2^S|=2^n&amp;lt;/math&amp;gt;. The proof needs another basic counting rule:  &#039;&#039;&amp;quot;the rule of sum&amp;quot;&#039;&#039;.&lt;br /&gt;
*&#039;&#039;&#039;The rule of sum&#039;&#039;&#039;: for any &#039;&#039;&#039;&#039;&#039;disjoint&#039;&#039;&#039;&#039;&#039; finite sets &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;, the cardinality of the union &amp;lt;math&amp;gt;|P\cup Q|=|P|+|Q|&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Define the function &amp;lt;math&amp;gt;f(n)=|2^{S_n}|&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;S_n=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; is an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. Our goal is to compute &amp;lt;math&amp;gt;f(n)&amp;lt;/math&amp;gt;. We prove the following recursion for &amp;lt;math&amp;gt;f(n)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma|&lt;br /&gt;
:&amp;lt;math&amp;gt;f(n)=2f(n-1)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Fix an element &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; be the set of subsets of &amp;lt;math&amp;gt;S_n&amp;lt;/math&amp;gt; that contain &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt; and let &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; be the set of subsets of &amp;lt;math&amp;gt;S_n&amp;lt;/math&amp;gt; that do not contain &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt;. It is obvious that &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; are disjoint (i.e. &amp;lt;math&amp;gt;U\cap V=\emptyset&amp;lt;/math&amp;gt;) and &amp;lt;math&amp;gt;2^{S_n}=U\cup V&amp;lt;/math&amp;gt;, because any subset of &amp;lt;math&amp;gt;S_n&amp;lt;/math&amp;gt; either contains &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt; or does not contain &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt; but not both.  &lt;br /&gt;
&lt;br /&gt;
Applying the rule of sum, &lt;br /&gt;
:&amp;lt;math&amp;gt;f(n)=|U\cup V|=|U|+|V|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The next observation is that &amp;lt;math&amp;gt;|U|=|V|=f(n-1)&amp;lt;/math&amp;gt;, because &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; is exactly the &amp;lt;math&amp;gt;2^{S_{n-1}}&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; is the set resulting from adding &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt; to every member of &amp;lt;math&amp;gt;2^{S_{n-1}}&amp;lt;/math&amp;gt;. Therefore, &lt;br /&gt;
:&amp;lt;math&amp;gt;f(n)=|U|+|V|=f(n-1)+f(n-1)=2f(n-1)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
The elementary case &amp;lt;math&amp;gt;f(0)=1&amp;lt;/math&amp;gt;, because &amp;lt;math&amp;gt;\emptyset&amp;lt;/math&amp;gt; has only one subset &amp;lt;math&amp;gt;\emptyset&amp;lt;/math&amp;gt;. Solving the recursion, we have that &amp;lt;math&amp;gt;|2^S|=f(n)=2^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Subsets of fixed size ===&lt;br /&gt;
We then count the number of subsets of fixed size of a set. Again, let &amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. We define &amp;lt;math&amp;gt;{S\choose k}&amp;lt;/math&amp;gt; to be the set of all &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-elements subsets (or &#039;&#039;&#039;&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subsets&#039;&#039;&#039;) of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;. Formally, &amp;lt;math&amp;gt;{S\choose k}=\{T\subseteq S\mid |T|=k\}&amp;lt;/math&amp;gt;. The set &amp;lt;math&amp;gt;{S\choose k}&amp;lt;/math&amp;gt; is sometimes called the &#039;&#039;&#039;&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-uniform&#039;&#039;&#039; of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We denote that &amp;lt;math&amp;gt;{n\choose k}=\left|{S\choose k}\right|&amp;lt;/math&amp;gt;. The notation &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; is read &amp;quot;&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; choose &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:&amp;lt;math&amp;gt;{n\choose k}=\frac{n(n-1)\cdots(n-k+1)}{k(k-1)\cdots 1}=\frac{n!}{k!(n-k)!}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
The number of &#039;&#039;&#039;ordered&#039;&#039;&#039; &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subsets of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set is &amp;lt;math&amp;gt;n(n-1)\cdots(n-k+1)&amp;lt;/math&amp;gt;. Every &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset has &amp;lt;math&amp;gt;k!=k(k-1)\cdots1&amp;lt;/math&amp;gt; ways to order it.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
;Some notations&lt;br /&gt;
* &amp;lt;math&amp;gt;n!&amp;lt;/math&amp;gt;, read &amp;quot;&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; factorial&amp;quot;, is defined as that &amp;lt;math&amp;gt;n!=n(n-1)(n-2)\cdots 1&amp;lt;/math&amp;gt;, with the convention that &amp;lt;math&amp;gt;0!=1&amp;lt;/math&amp;gt;.&lt;br /&gt;
* &amp;lt;math&amp;gt;n(n-1)\cdots(n-k+1)=\frac{n!}{(n-k)!}&amp;lt;/math&amp;gt; is usually denoted as &amp;lt;math&amp;gt;(n)_k\,&amp;lt;/math&amp;gt;, read &amp;quot;&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; lower factorial &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;binomial coefficient&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Proposition|&lt;br /&gt;
# &amp;lt;math&amp;gt;{n\choose k}={n\choose n-k}&amp;lt;/math&amp;gt;;&lt;br /&gt;
# &amp;lt;math&amp;gt;\sum_{k=0}^n {n\choose k}=2^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
1. We give two proofs for the first equation:&lt;br /&gt;
:(1) (numerical proof)&lt;br /&gt;
::&amp;lt;math&amp;gt;{n\choose k}=\frac{n!}{k!(n-k)!}={n\choose n-k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:(2) (combinatorial proof)&lt;br /&gt;
::Choosing &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; elements from an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set is equivalent to choosing the &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; elements to leave out. Formally, every &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset &amp;lt;math&amp;gt;T\in{S\choose k}&amp;lt;/math&amp;gt; is uniquely specified by its complement &amp;lt;math&amp;gt;S\setminus T\in {S\choose n-k}&amp;lt;/math&amp;gt;, and the same holds for &amp;lt;math&amp;gt;(n-k)&amp;lt;/math&amp;gt;-subsets, thus we have a bijection between &amp;lt;math&amp;gt;{S\choose k}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;{S\choose n-k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
2. The second equation can also be proved in different ways, but the combinatorial proof is much easier. For an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;, it is obvious that we can enumerate all subsets of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; by enumerating &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subsets for every possible size &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, i.e. it holds that&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
2^S=\bigcup_{k=0}^n{S\choose k}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
For different &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;{S\choose k}&amp;lt;/math&amp;gt; are obviously disjoint. By the rule of sum,&lt;br /&gt;
:&amp;lt;math&amp;gt;2^n=|2^S|=\left|\bigcup_{k=0}^n{S\choose k}\right|=\sum_{k=0}^n\left|{S\choose k}\right|=\sum_{k=0}^n {n\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; is called binomial coefficient for a reason. A binomial is a polynomial with two terms (&amp;quot;poly-&amp;quot; means many, and &amp;quot;bi-&amp;quot; means two, like in &amp;quot;binary&amp;quot;, &amp;quot;bipartite&amp;quot;, etc). The following celebrated &#039;&#039;&#039;Binomial Theorem&#039;&#039;&#039; states that if a power of a binomial is expanded, the coefficients in the resulting polynomial are the binomial coefficients.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Binomial theorem)|&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x)^n=\sum_{k=0}^n{n\choose k}x^k&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Write &amp;lt;math&amp;gt;(1+x)^n&amp;lt;/math&amp;gt; as the product of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; factors&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x)(1+x)\cdots (1+x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
The term &amp;lt;math&amp;gt;x^k&amp;lt;/math&amp;gt; is obtained by choosing &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; factors and 1 from the rest &amp;lt;math&amp;gt;(n-k)&amp;lt;/math&amp;gt; factors. There are &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; ways of choosing these &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; factors, so the coefficient of &amp;lt;math&amp;gt;x^k&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The following proposition has an easy proof due to the binomial theorem.&lt;br /&gt;
{{Theorem| Proposition|&lt;br /&gt;
:For &amp;lt;math&amp;gt;n&amp;gt;0&amp;lt;/math&amp;gt;, the numbers of subsets of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set of even and of odd cardinality are equal.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Set &amp;lt;math&amp;gt;x=-1&amp;lt;/math&amp;gt; in the binomial theorem.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
0=(1-1)^n=\sum_{k=0}^n{n\choose k}(-1)^k=\sum_{\overset{0\le k\le n}{k \text{ even}}}{n\choose k}-\sum_{\overset{0\le k\le n}{k \text{ odd}}}{n\choose k},&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
therefore&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{\overset{0\le k\le n}{k \text{ even}}}{n\choose k}=\sum_{\overset{0\le k\le n}{k \text{ odd}}}{n\choose k}.&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
For counting problems, what we care about are &#039;&#039;numbers&#039;&#039;. In the binomial theorem, a formal &#039;&#039;variable&#039;&#039; &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is introduced. It looks having nothing to do with our problem, but turns out to be very useful. This idea of introducing a formal variable is the basic idea of some advanced counting techniques, which will be discussed in future classes.&lt;br /&gt;
&lt;br /&gt;
=== Compositions of an integer ===&lt;br /&gt;
A &#039;&#039;&#039;composition&#039;&#039;&#039; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is an expression of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; as an &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&#039;&#039;ordered&#039;&#039;&amp;lt;/font&amp;gt; sum of &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&#039;&#039;positive&#039;&#039;&amp;lt;/font&amp;gt; integers. A &#039;&#039;&#039;&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition&#039;&#039;&#039; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is a composition of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with exactly &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; positive summands. &lt;br /&gt;
&lt;br /&gt;
Formally, a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-tuple &amp;lt;math&amp;gt;(a_1,a_2,\ldots,a_k)\in\{1,2,\ldots,n\}^k&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;a_1+a_2+\cdots+a_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Suppose we have &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; identical balls in a line. A &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition partitions these &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; balls into &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; &#039;&#039;nonempty&#039;&#039; sets, illustrated as follows.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{array}{c|cc|c|c|ccc|cc}&lt;br /&gt;
\bigcirc \,&amp;amp;\, \bigcirc \,&amp;amp; \bigcirc \,&amp;amp;\, \bigcirc \,&amp;amp;\, \bigcirc \,&amp;amp;\, \bigcirc &amp;amp;\, \bigcirc &amp;amp;\, \bigcirc \,&amp;amp;\, \bigcirc \,&amp;amp; \bigcirc&lt;br /&gt;
\end{array}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; equals the number of ways we put &amp;lt;math&amp;gt;k-1&amp;lt;/math&amp;gt; bars &amp;quot;&amp;lt;math&amp;gt;|&amp;lt;/math&amp;gt;&amp;quot; into &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt; slots &amp;quot;&amp;lt;math&amp;gt;\sqcup&amp;lt;/math&amp;gt;&amp;quot;, where each slot has at most one bar (because all the summands &amp;lt;math&amp;gt;a_i&amp;gt;0&amp;lt;/math&amp;gt;):&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
which is equal to the number of ways of choosing &amp;lt;math&amp;gt;k-1&amp;lt;/math&amp;gt; slots out of &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt; slots, which is &amp;lt;math&amp;gt;{n-1\choose k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This graphic argument can be expressed as a formal proof. We construct a bijection between the set of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;{\{1,2,\ldots,n-1\}\choose k-1}&amp;lt;/math&amp;gt; as follows. &lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; be a mapping that given a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition &amp;lt;math&amp;gt;(a_1,a_2,\ldots,a_k)&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\phi((a_1,a_2,\ldots,a_k))&lt;br /&gt;
&amp;amp;=\{a_1,\,\,a_1+a_2,\,\,a_1+a_2+a_3,\,\,\ldots,\,\,a_1+a_2+\cdots+a_{k-1}\}\\&lt;br /&gt;
&amp;amp;=\left\{\sum_{i=1}^ja_i\,\,\bigg|\,\, 1\le j&amp;lt;k\right\}.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; maps every &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition to a &amp;lt;math&amp;gt;(k-1)&amp;lt;/math&amp;gt;-subset of &amp;lt;math&amp;gt;\{1,2,\ldots,n-1\}&amp;lt;/math&amp;gt;. It is easy to verify that &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; is a bijection, thus the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;{n-1\choose k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
----&lt;br /&gt;
The number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is equal to the number of &#039;&#039;positive&#039;&#039; integer solutions to &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;. This suggests us to relax the constraint and count the number of &#039;&#039;nonnegative&#039;&#039; integer solutions to &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;. We call such a solution a &#039;&#039;&#039;weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition&#039;&#039;&#039; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Formally, a weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is a tuple &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)\in[n+1]^k&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Given a weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, if we set &amp;lt;math&amp;gt;y_i=x_i+1&amp;lt;/math&amp;gt; for every &amp;lt;math&amp;gt;1\le i\le k&amp;lt;/math&amp;gt;, then &amp;lt;math&amp;gt;y_i&amp;gt;0&amp;lt;/math&amp;gt; and &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
y_1+y_2+\cdots +y_k&lt;br /&gt;
&amp;amp;=(x_1+1)+(x_2+1)+\cdots+(x_k+1)&amp;amp;=n+k,&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
i.e., &amp;lt;math&amp;gt;(y_1,y_2,\ldots,y_k)&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition of &amp;lt;math&amp;gt;n+k&amp;lt;/math&amp;gt;. It is easy to see that it defines a bijection between weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n+k&amp;lt;/math&amp;gt;. Therefore, the number of weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;{n+k-1\choose k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
----&lt;br /&gt;
We now count the number of nonnegative integer solutions to &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k\le n&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;x_{k+1}=n-(x_1+x_2+\cdots+x_k)&amp;lt;/math&amp;gt;. Then &amp;lt;math&amp;gt;x_{k+1}\ge 0&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_1+x_2+\ldots+x_k+x_{k+1}=n&amp;lt;/math&amp;gt;. &lt;br /&gt;
The problem is transformed to that counting the number of nonnegative integer solutions to the above equation. The answer is &amp;lt;math&amp;gt;{n+k\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Multisets ===&lt;br /&gt;
A &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is sometimes called a &#039;&#039;&#039;&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-combination of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; without repetitions&#039;&#039;&#039;. This suggests the problem of counting the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-combinations of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; &#039;&#039;&#039;&#039;&#039;with repetitions&#039;&#039;&#039;&#039;&#039;; that is, we choose &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; elements of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;, disregarding order and allowing repeated elements. &lt;br /&gt;
&lt;br /&gt;
;Example&lt;br /&gt;
:&amp;lt;math&amp;gt;S=\{1,2,3,4\}&amp;lt;/math&amp;gt;. All &amp;lt;math&amp;gt;3&amp;lt;/math&amp;gt;-combination without repetitions are &lt;br /&gt;
::&amp;lt;math&amp;gt;\{1,2,3\},\{1,2,4\},\{1,3,4\},\{2,3,4\}\,&amp;lt;/math&amp;gt;. &lt;br /&gt;
:Allowing repetitions, we also include the following 3-combinations:&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
&amp;amp;\{1,1,1\},\{1,1,2\},\{1,1,3\},\{1,1,4\},\{1,2,2\},\{1,3,3\},\{1,4,4\},\\&lt;br /&gt;
&amp;amp;\{2,2,2\},\{2,2,3\},\{2,2,4\},\{2,3,3\},\{2,4,4\},\\&lt;br /&gt;
&amp;amp;\{3,3,3\},\{3,3,4\},\{3,4,4\}\\&lt;br /&gt;
&amp;amp;\{4,4,4\}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Combinations with repetitions can be formally defined as &#039;&#039;&#039;multisets&#039;&#039;&#039;. A multiset is a set with repeated elements. Formally, a multiset &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; on a set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is a function &amp;lt;math&amp;gt;m:S\rightarrow \mathbb{N}&amp;lt;/math&amp;gt;. For any element &amp;lt;math&amp;gt;x\in S&amp;lt;/math&amp;gt;, the integer &amp;lt;math&amp;gt;m(x)\ge 0&amp;lt;/math&amp;gt; is the number of repetitions of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt;, called the &#039;&#039;&#039;multiplicity&#039;&#039;&#039; of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;. The sum of multiplicities &amp;lt;math&amp;gt;\sum_{x\in S}m(x)&amp;lt;/math&amp;gt; is called the &#039;&#039;&#039;cardinality&#039;&#039;&#039; of &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; and is denoted as &amp;lt;math&amp;gt;|M|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multiset on a set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is a multiset &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|M|=k&amp;lt;/math&amp;gt;. It is obvious that a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-combination of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; with repetition is simply a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multiset on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The set of all &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multisets on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is denoted &amp;lt;math&amp;gt;\left({S\choose k}\right)&amp;lt;/math&amp;gt;. Assuming that &amp;lt;math&amp;gt;n=|S|&amp;lt;/math&amp;gt;, denote &amp;lt;math&amp;gt;\left({n\choose k}\right)=\left|\left({S\choose k}\right)\right|&amp;lt;/math&amp;gt;, which is the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-combinations of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set with repetitions.&lt;br /&gt;
&lt;br /&gt;
Believe it or not: we have already evaluated the number  &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;z_i=m(x_i)&amp;lt;/math&amp;gt;, then &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt; is the number of nonnegative integer solutions to &amp;lt;math&amp;gt;z_1+z_2+\cdots+z_n=k&amp;lt;/math&amp;gt;, which is the number of weak &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, which we have seen is &amp;lt;math&amp;gt;{n+k-1\choose n-1}={n+k-1\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
There is a direct combinatorial proof that &amp;lt;math&amp;gt;\left({n\choose k}\right)={n+k-1\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Given a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multiset &amp;lt;math&amp;gt;0\le a_0\le a_1\le\cdots\le a_{k-1}\le n-1&amp;lt;/math&amp;gt; on &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt;, then defining &amp;lt;math&amp;gt;b_i=a_i+i&amp;lt;/math&amp;gt;, we see that &amp;lt;math&amp;gt;\{b_0,b_1,\ldots,b_{k-1}\}&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset of &amp;lt;math&amp;gt;[n+k-1]&amp;lt;/math&amp;gt;. Conversely, given a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset &amp;lt;math&amp;gt;0\le b_0\le b_1\le\cdots\le b_{k-1}\le n+k-2&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;[n+k-1]&amp;lt;/math&amp;gt;, then defining &amp;lt;math&amp;gt;a_i=b_i-i&amp;lt;/math&amp;gt;, we have that &amp;lt;math&amp;gt;\{b_0,b_1,\ldots,b_{k-1}\}&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multiset on &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt;. Therefore, we have a bijection between &amp;lt;math&amp;gt;\left({[n]\choose k}\right)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;{[n+k-1]\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Multinomial coefficients ===&lt;br /&gt;
&lt;br /&gt;
== Permutations and Partitions ==&lt;br /&gt;
&lt;br /&gt;
== The twelvfold way ==&lt;br /&gt;
We consider a very fundamental counting framework: counting functions &amp;lt;math&amp;gt;f:N\rightarrow M&amp;lt;/math&amp;gt;. We can define different counting problems according to the types of mapping (1-1, on-to, arbitrary), and the types of the domain and the range (distinguishable, indistinguishable).&lt;br /&gt;
* Distinguishability of set:&lt;br /&gt;
* Types of mapping:&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot;  cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;10&amp;quot; rules=&amp;quot;all&amp;quot;  style=&amp;quot;margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Elements of &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt;&lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Elements of &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; &lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Any &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; &lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Injective (1-1) &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; &lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Surjective (on-to) &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;distinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;distinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;m^n\,&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\left(m\right)_n&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;m!S(n, m)\,&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;indistinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;distinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\left({m\choose n}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;|&amp;lt;math&amp;gt;{m\choose n}&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;|&amp;lt;math&amp;gt;\left({m\choose n-m}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;distinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;indistinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\sum_{k=1}^m S(n,k)&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\begin{cases}1 &amp;amp; \mbox{if }n\le m\\ 0&amp;amp; \mbox{if }n&amp;gt;m\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;S(n,m)\,&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;indistinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;indistinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\sum_{k=1}^m p_k(n)&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\begin{cases}1 &amp;amp; \mbox{if }n\le m\\ 0&amp;amp; \mbox{if }n&amp;gt;m\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;p_m(n)\,&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot;  cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;10&amp;quot; rules=&amp;quot;all&amp;quot;  style=&amp;quot;margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | balls per bin&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | unrestricted &lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | ≤ 1&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | ≥ 1&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; labeled balls, &amp;lt;br&amp;gt;&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; labeled bins&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-tuples &amp;lt;br&amp;gt;of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; things&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-permutations &amp;lt;br&amp;gt;of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; things&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partition of &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt; into &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; ordered parts&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; unlabeled balls, &amp;lt;br&amp;gt;&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; labeled bins&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-combinations of &amp;lt;math&amp;gt;[m]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;with repetitions&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-combinations of &amp;lt;math&amp;gt;[m]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt; without repetitions&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; labeled balls, &amp;lt;br&amp;gt;&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; unlabeled bins&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partitions of &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;\le m&amp;lt;/math&amp;gt; parts&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; pigeons &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; holes&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partitions of &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;\le m&amp;lt;/math&amp;gt; parts&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; unlabeled balls, &amp;lt;br&amp;gt;&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; unlabeled bins&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partitions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;\le m&amp;lt;/math&amp;gt; parts&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; pigeons &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; holes&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partitions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; parts&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
* &#039;&#039;Stanley,&#039;&#039; Enumerative Combinatorics, Volume 1, Chapter 1.&lt;/div&gt;</summary>
		<author><name>0:0:0:0:0:0:0:1</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Basic_enumeration&amp;diff=2890</id>
		<title>Combinatorics (Fall 2010)/Basic enumeration</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Basic_enumeration&amp;diff=2890"/>
		<updated>2010-07-10T07:18:50Z</updated>

		<summary type="html">&lt;p&gt;0:0:0:0:0:0:0:1: /* Subsets */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Counting Problems ==&lt;br /&gt;
&lt;br /&gt;
== Sets and Multisets ==&lt;br /&gt;
=== Subsets ===&lt;br /&gt;
We want to count the number of subsets of a set.&lt;br /&gt;
&lt;br /&gt;
Let&amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set, or &#039;&#039;&#039;&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set&#039;&#039;&#039; for short. &lt;br /&gt;
Let &amp;lt;math&amp;gt;2^S=\{T\mid T\subset S\}&amp;lt;/math&amp;gt; denote the set of all subset of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;. &amp;lt;math&amp;gt;2^S&amp;lt;/math&amp;gt; is called the &#039;&#039;&#039;power set&#039;&#039;&#039; of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We give a combinatorial proof that &amp;lt;math&amp;gt;|2^S|=2^n&amp;lt;/math&amp;gt;. We observe that every subset &amp;lt;math&amp;gt;T\in 2^S&amp;lt;/math&amp;gt; corresponds to a unique bit-vector &amp;lt;math&amp;gt;v\in\{0,1\}^S&amp;lt;/math&amp;gt;, such that each bit &amp;lt;math&amp;gt;v_i&amp;lt;/math&amp;gt; indicates whether &amp;lt;math&amp;gt;x_i\in S&amp;lt;/math&amp;gt;. Formally, define a map &amp;lt;math&amp;gt;\phi:2^S\rightarrow\{0,1\}^n&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;\phi(T)=(v_1,v_2,\ldots,v_n)&amp;lt;/math&amp;gt;, where&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
v_i=\begin{cases}&lt;br /&gt;
1 &amp;amp; \mbox{if }x_i\in T\\&lt;br /&gt;
0 &amp;amp; \mbox{if }x_i\not\in T.&lt;br /&gt;
\end{cases}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The map &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; is a &#039;&#039;&#039;bijection&#039;&#039;&#039; (a 1-1 correspondence). The proof that &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; is a bijection is left as an exercise.&lt;br /&gt;
&lt;br /&gt;
Since there is a bijection between &amp;lt;math&amp;gt;2^S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\{0,1\}^n&amp;lt;/math&amp;gt;, it holds that &amp;lt;math&amp;gt;|2^S|=|\{0,1\}^n|=2^n\,&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Here we apply &#039;&#039;&amp;quot;the rule of bijection&amp;quot;&#039;&#039;.&lt;br /&gt;
*&#039;&#039;&#039;The rule of bijection&#039;&#039;&#039;: if there exists a bijection between finite sets &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;, then &amp;lt;math&amp;gt;|P|=|Q|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we know that &amp;lt;math&amp;gt;|\{0,1\}^n|=2^n\,&amp;lt;/math&amp;gt;? We use &#039;&#039;&amp;quot;the rule of product&amp;quot;&#039;&#039;.&lt;br /&gt;
*&#039;&#039;&#039;The rule of product&#039;&#039;&#039;: for any finite sets &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;, the cardinality of the Cartesian product &amp;lt;math&amp;gt;|P\times Q|=|P|\cdot|Q|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To count the size of &amp;lt;math&amp;gt;\{0,1\}^n\,&amp;lt;/math&amp;gt;, we write &amp;lt;math&amp;gt;\{0,1\}^n=\{0,1\}\times\{0,1\}^{n-1}&amp;lt;/math&amp;gt;, thus &amp;lt;math&amp;gt;|\{0,1\}^n|=2|\{0,1\}^{n-1}|\,&amp;lt;/math&amp;gt;. Solving the recursion, we have that &amp;lt;math&amp;gt;|\{0,1\}^n|=2^n\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are two elements of the proof:&lt;br /&gt;
* Find a 1-1 correspondence between subsets of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set and &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-bit vectors.&lt;br /&gt;
: An application of this in Computer Science is that we can use bit-array as a data structure for sets: any set defined over a &#039;&#039;&#039;universe&#039;&#039;&#039; &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; can be represented by an array of &amp;lt;math&amp;gt;|U|&amp;lt;/math&amp;gt; bits.&lt;br /&gt;
* The rule of bijection: if there is a 1-1 correspondence between two sets, then their cardinalities are the same.&lt;br /&gt;
&lt;br /&gt;
Many counting problems are solved by establishing a bijection between the set to be counted and some easy-to-count set. This kind of proofs are usually called (non-rigorously) &#039;&#039;&#039;combinatorial proofs&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
We give an alternative proof that &amp;lt;math&amp;gt;|2^S|=2^n&amp;lt;/math&amp;gt;. The proof needs another basic counting rule:  &#039;&#039;&#039;&amp;quot;the rule of sum&amp;quot;&#039;&#039;&#039;.&lt;br /&gt;
*&#039;&#039;&#039;The rule of sum&#039;&#039;&#039;: for any &#039;&#039;&#039;&#039;&#039;disjoint&#039;&#039;&#039;&#039;&#039; finite sets &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;, the cardinality of the union &amp;lt;math&amp;gt;|P\cup Q|=|P|+|Q|&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Define the function &amp;lt;math&amp;gt;f(n)=|2^{S_n}|&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;S_n=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; is an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. Our goal is to compute &amp;lt;math&amp;gt;f(n)&amp;lt;/math&amp;gt;. We prove the following recursion for &amp;lt;math&amp;gt;f(n)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma|&lt;br /&gt;
:&amp;lt;math&amp;gt;f(n)=2f(n-1)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Fix an element &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; be the set of subsets of &amp;lt;math&amp;gt;S_n&amp;lt;/math&amp;gt; that contain &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt; and let &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; be the set of subsets of &amp;lt;math&amp;gt;S_n&amp;lt;/math&amp;gt; that do not contain &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt;. It is obvious that &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; are disjoint (i.e. &amp;lt;math&amp;gt;U\cap V=\emptyset&amp;lt;/math&amp;gt;) and &amp;lt;math&amp;gt;2^{S_n}=U\cup V&amp;lt;/math&amp;gt;, because any subset of &amp;lt;math&amp;gt;S_n&amp;lt;/math&amp;gt; either contains &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt; or does not contain &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt; but not both.  &lt;br /&gt;
&lt;br /&gt;
Applying the rule of sum, &lt;br /&gt;
:&amp;lt;math&amp;gt;f(n)=|U\cup V|=|U|+|V|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The next observation is that &amp;lt;math&amp;gt;|U|=|V|=f(n-1)&amp;lt;/math&amp;gt;, because &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; is exactly the &amp;lt;math&amp;gt;2^{S_{n-1}}&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; is the set resulting from adding &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt; to every member of &amp;lt;math&amp;gt;2^{S_{n-1}}&amp;lt;/math&amp;gt;. Therefore, &lt;br /&gt;
:&amp;lt;math&amp;gt;f(n)=|U|+|V|=f(n-1)+f(n-1)=2f(n-1)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
The elementary case &amp;lt;math&amp;gt;f(0)=1&amp;lt;/math&amp;gt;, because &amp;lt;math&amp;gt;\emptyset&amp;lt;/math&amp;gt; has only one subset &amp;lt;math&amp;gt;\emptyset&amp;lt;/math&amp;gt;. Solving the recursion, we have that &amp;lt;math&amp;gt;|2^S|=f(n)=2^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Subsets of fixed size ===&lt;br /&gt;
We then count the number of subsets of fixed size of a set. Again, let &amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. We define &amp;lt;math&amp;gt;{S\choose k}&amp;lt;/math&amp;gt; to be the set of all &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-elements subsets (or &#039;&#039;&#039;&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subsets&#039;&#039;&#039;) of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;. Formally, &amp;lt;math&amp;gt;{S\choose k}=\{T\subseteq S\mid |T|=k\}&amp;lt;/math&amp;gt;. The set &amp;lt;math&amp;gt;{S\choose k}&amp;lt;/math&amp;gt; is sometimes called the &#039;&#039;&#039;&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-uniform&#039;&#039;&#039; of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We denote that &amp;lt;math&amp;gt;{n\choose k}=\left|{S\choose k}\right|&amp;lt;/math&amp;gt;. The notation &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; is read &amp;quot;&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; choose &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:&amp;lt;math&amp;gt;{n\choose k}=\frac{n(n-1)\cdots(n-k+1)}{k(k-1)\cdots 1}=\frac{n!}{k!(n-k)!}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
The number of &#039;&#039;&#039;ordered&#039;&#039;&#039; &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subsets of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set is &amp;lt;math&amp;gt;n(n-1)\cdots(n-k+1)&amp;lt;/math&amp;gt;. Every &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset has &amp;lt;math&amp;gt;k!=k(k-1)\cdots1&amp;lt;/math&amp;gt; ways to order it.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
;Some notations&lt;br /&gt;
* &amp;lt;math&amp;gt;n!&amp;lt;/math&amp;gt;, read &amp;quot;&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; factorial&amp;quot;, is defined as that &amp;lt;math&amp;gt;n!=n(n-1)(n-2)\cdots 1&amp;lt;/math&amp;gt;, with the convention that &amp;lt;math&amp;gt;0!=1&amp;lt;/math&amp;gt;.&lt;br /&gt;
* &amp;lt;math&amp;gt;n(n-1)\cdots(n-k+1)=\frac{n!}{(n-k)!}&amp;lt;/math&amp;gt; is usually denoted as &amp;lt;math&amp;gt;(n)_k\,&amp;lt;/math&amp;gt;, read &amp;quot;&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; lower factorial &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;binomial coefficient&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Proposition|&lt;br /&gt;
# &amp;lt;math&amp;gt;{n\choose k}={n\choose n-k}&amp;lt;/math&amp;gt;;&lt;br /&gt;
# &amp;lt;math&amp;gt;\sum_{k=0}^n {n\choose k}=2^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
1. We give two proofs for the first equation:&lt;br /&gt;
:(1) (numerical proof)&lt;br /&gt;
::&amp;lt;math&amp;gt;{n\choose k}=\frac{n!}{k!(n-k)!}={n\choose n-k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:(2) (combinatorial proof)&lt;br /&gt;
::Choosing &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; elements from an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set is equivalent to choosing the &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; elements to leave out. Formally, every &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset &amp;lt;math&amp;gt;T\in{S\choose k}&amp;lt;/math&amp;gt; is uniquely specified by its complement &amp;lt;math&amp;gt;S\setminus T\in {S\choose n-k}&amp;lt;/math&amp;gt;, and the same holds for &amp;lt;math&amp;gt;(n-k)&amp;lt;/math&amp;gt;-subsets, thus we have a bijection between &amp;lt;math&amp;gt;{S\choose k}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;{S\choose n-k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
2. The second equation can also be proved in different ways, but the combinatorial proof is much easier. For an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;, it is obvious that we can enumerate all subsets of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; by enumerating &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subsets for every possible size &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, i.e. it holds that&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
2^S=\bigcup_{k=0}^n{S\choose k}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
For different &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;{S\choose k}&amp;lt;/math&amp;gt; are obviously disjoint. By the rule of sum,&lt;br /&gt;
:&amp;lt;math&amp;gt;2^n=|2^S|=\left|\bigcup_{k=0}^n{S\choose k}\right|=\sum_{k=0}^n\left|{S\choose k}\right|=\sum_{k=0}^n {n\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; is called binomial coefficient for a reason. A binomial is a polynomial with two terms (&amp;quot;poly-&amp;quot; means many, and &amp;quot;bi-&amp;quot; means two, like in &amp;quot;binary&amp;quot;, &amp;quot;bipartite&amp;quot;, etc). The following celebrated &#039;&#039;&#039;Binomial Theorem&#039;&#039;&#039; states that if a power of a binomial is expanded, the coefficients in the resulting polynomial are the binomial coefficients.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Binomial theorem)|&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x)^n=\sum_{k=0}^n{n\choose k}x^k&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Write &amp;lt;math&amp;gt;(1+x)^n&amp;lt;/math&amp;gt; as the product of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; factors&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x)(1+x)\cdots (1+x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
The term &amp;lt;math&amp;gt;x^k&amp;lt;/math&amp;gt; is obtained by choosing &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; factors and 1 from the rest &amp;lt;math&amp;gt;(n-k)&amp;lt;/math&amp;gt; factors. There are &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; ways of choosing these &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; factors, so the coefficient of &amp;lt;math&amp;gt;x^k&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The following proposition has an easy proof due to the binomial theorem.&lt;br /&gt;
{{Theorem| Proposition|&lt;br /&gt;
:For &amp;lt;math&amp;gt;n&amp;gt;0&amp;lt;/math&amp;gt;, the numbers of subsets of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set of even and of odd cardinality are equal.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Set &amp;lt;math&amp;gt;x=-1&amp;lt;/math&amp;gt; in the binomial theorem.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
0=(1-1)^n=\sum_{k=0}^n{n\choose k}(-1)^k=\sum_{\overset{0\le k\le n}{k \text{ even}}}{n\choose k}-\sum_{\overset{0\le k\le n}{k \text{ odd}}}{n\choose k},&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
therefore&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{\overset{0\le k\le n}{k \text{ even}}}{n\choose k}=\sum_{\overset{0\le k\le n}{k \text{ odd}}}{n\choose k}.&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
For counting problems, what we care about are &#039;&#039;numbers&#039;&#039;. In the binomial theorem, a formal &#039;&#039;variable&#039;&#039; &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is introduced. It looks having nothing to do with our problem, but turns out to be very useful. This idea of introducing a formal variable is the basic idea of some advanced counting techniques, which will be discussed in future classes.&lt;br /&gt;
&lt;br /&gt;
=== Compositions of an integer ===&lt;br /&gt;
A &#039;&#039;&#039;composition&#039;&#039;&#039; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is an expression of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; as an &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&#039;&#039;ordered&#039;&#039;&amp;lt;/font&amp;gt; sum of &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&#039;&#039;positive&#039;&#039;&amp;lt;/font&amp;gt; integers. A &#039;&#039;&#039;&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition&#039;&#039;&#039; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is a composition of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with exactly &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; positive summands. &lt;br /&gt;
&lt;br /&gt;
Formally, a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-tuple &amp;lt;math&amp;gt;(a_1,a_2,\ldots,a_k)\in\{1,2,\ldots,n\}^k&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;a_1+a_2+\cdots+a_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Suppose we have &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; identical balls in a line. A &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition partitions these &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; balls into &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; &#039;&#039;nonempty&#039;&#039; sets, illustrated as follows.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{array}{c|cc|c|c|ccc|cc}&lt;br /&gt;
\bigcirc \,&amp;amp;\, \bigcirc \,&amp;amp; \bigcirc \,&amp;amp;\, \bigcirc \,&amp;amp;\, \bigcirc \,&amp;amp;\, \bigcirc &amp;amp;\, \bigcirc &amp;amp;\, \bigcirc \,&amp;amp;\, \bigcirc \,&amp;amp; \bigcirc&lt;br /&gt;
\end{array}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; equals the number of ways we put &amp;lt;math&amp;gt;k-1&amp;lt;/math&amp;gt; bars &amp;quot;&amp;lt;math&amp;gt;|&amp;lt;/math&amp;gt;&amp;quot; into &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt; slots &amp;quot;&amp;lt;math&amp;gt;\sqcup&amp;lt;/math&amp;gt;&amp;quot;, where each slot has at most one bar (because all the summands &amp;lt;math&amp;gt;a_i&amp;gt;0&amp;lt;/math&amp;gt;):&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
which is equal to the number of ways of choosing &amp;lt;math&amp;gt;k-1&amp;lt;/math&amp;gt; slots out of &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt; slots, which is &amp;lt;math&amp;gt;{n-1\choose k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This graphic argument can be expressed as a formal proof. We construct a bijection between the set of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;{\{1,2,\ldots,n-1\}\choose k-1}&amp;lt;/math&amp;gt; as follows. &lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; be a mapping that given a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition &amp;lt;math&amp;gt;(a_1,a_2,\ldots,a_k)&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\phi((a_1,a_2,\ldots,a_k))&lt;br /&gt;
&amp;amp;=\{a_1,\,\,a_1+a_2,\,\,a_1+a_2+a_3,\,\,\ldots,\,\,a_1+a_2+\cdots+a_{k-1}\}\\&lt;br /&gt;
&amp;amp;=\left\{\sum_{i=1}^ja_i\,\,\bigg|\,\, 1\le j&amp;lt;k\right\}.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; maps every &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition to a &amp;lt;math&amp;gt;(k-1)&amp;lt;/math&amp;gt;-subset of &amp;lt;math&amp;gt;\{1,2,\ldots,n-1\}&amp;lt;/math&amp;gt;. It is easy to verify that &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; is a bijection, thus the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;{n-1\choose k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
----&lt;br /&gt;
The number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is equal to the number of &#039;&#039;positive&#039;&#039; integer solutions to &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;. This suggests us to relax the constraint and count the number of &#039;&#039;nonnegative&#039;&#039; integer solutions to &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;. We call such a solution a &#039;&#039;&#039;weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition&#039;&#039;&#039; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Formally, a weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is a tuple &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)\in[n+1]^k&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Given a weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, if we set &amp;lt;math&amp;gt;y_i=x_i+1&amp;lt;/math&amp;gt; for every &amp;lt;math&amp;gt;1\le i\le k&amp;lt;/math&amp;gt;, then &amp;lt;math&amp;gt;y_i&amp;gt;0&amp;lt;/math&amp;gt; and &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
y_1+y_2+\cdots +y_k&lt;br /&gt;
&amp;amp;=(x_1+1)+(x_2+1)+\cdots+(x_k+1)&amp;amp;=n+k,&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
i.e., &amp;lt;math&amp;gt;(y_1,y_2,\ldots,y_k)&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition of &amp;lt;math&amp;gt;n+k&amp;lt;/math&amp;gt;. It is easy to see that it defines a bijection between weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n+k&amp;lt;/math&amp;gt;. Therefore, the number of weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;{n+k-1\choose k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
----&lt;br /&gt;
We now count the number of nonnegative integer solutions to &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k\le n&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;x_{k+1}=n-(x_1+x_2+\cdots+x_k)&amp;lt;/math&amp;gt;. Then &amp;lt;math&amp;gt;x_{k+1}\ge 0&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_1+x_2+\ldots+x_k+x_{k+1}=n&amp;lt;/math&amp;gt;. &lt;br /&gt;
The problem is transformed to that counting the number of nonnegative integer solutions to the above equation. The answer is &amp;lt;math&amp;gt;{n+k\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Multisets ===&lt;br /&gt;
A &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is sometimes called a &#039;&#039;&#039;&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-combination of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; without repetitions&#039;&#039;&#039;. This suggests the problem of counting the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-combinations of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; &#039;&#039;&#039;&#039;&#039;with repetitions&#039;&#039;&#039;&#039;&#039;; that is, we choose &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; elements of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;, disregarding order and allowing repeated elements. &lt;br /&gt;
&lt;br /&gt;
;Example&lt;br /&gt;
:&amp;lt;math&amp;gt;S=\{1,2,3,4\}&amp;lt;/math&amp;gt;. All &amp;lt;math&amp;gt;3&amp;lt;/math&amp;gt;-combination without repetitions are &lt;br /&gt;
::&amp;lt;math&amp;gt;\{1,2,3\},\{1,2,4\},\{1,3,4\},\{2,3,4\}\,&amp;lt;/math&amp;gt;. &lt;br /&gt;
:Allowing repetitions, we also include the following 3-combinations:&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
&amp;amp;\{1,1,1\},\{1,1,2\},\{1,1,3\},\{1,1,4\},\{1,2,2\},\{1,3,3\},\{1,4,4\},\\&lt;br /&gt;
&amp;amp;\{2,2,2\},\{2,2,3\},\{2,2,4\},\{2,3,3\},\{2,4,4\},\\&lt;br /&gt;
&amp;amp;\{3,3,3\},\{3,3,4\},\{3,4,4\}\\&lt;br /&gt;
&amp;amp;\{4,4,4\}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Combinations with repetitions can be formally defined as &#039;&#039;&#039;multisets&#039;&#039;&#039;. A multiset is a set with repeated elements. Formally, a multiset &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; on a set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is a function &amp;lt;math&amp;gt;m:S\rightarrow \mathbb{N}&amp;lt;/math&amp;gt;. For any element &amp;lt;math&amp;gt;x\in S&amp;lt;/math&amp;gt;, the integer &amp;lt;math&amp;gt;m(x)\ge 0&amp;lt;/math&amp;gt; is the number of repetitions of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt;, called the &#039;&#039;&#039;multiplicity&#039;&#039;&#039; of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;. The sum of multiplicities &amp;lt;math&amp;gt;\sum_{x\in S}m(x)&amp;lt;/math&amp;gt; is called the &#039;&#039;&#039;cardinality&#039;&#039;&#039; of &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; and is denoted as &amp;lt;math&amp;gt;|M|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multiset on a set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is a multiset &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|M|=k&amp;lt;/math&amp;gt;. It is obvious that a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-combination of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; with repetition is simply a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multiset on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The set of all &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multisets on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is denoted &amp;lt;math&amp;gt;\left({S\choose k}\right)&amp;lt;/math&amp;gt;. Assuming that &amp;lt;math&amp;gt;n=|S|&amp;lt;/math&amp;gt;, denote &amp;lt;math&amp;gt;\left({n\choose k}\right)=\left|\left({S\choose k}\right)\right|&amp;lt;/math&amp;gt;, which is the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-combinations of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set with repetitions.&lt;br /&gt;
&lt;br /&gt;
Believe it or not: we have already evaluated the number  &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;z_i=m(x_i)&amp;lt;/math&amp;gt;, then &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt; is the number of nonnegative integer solutions to &amp;lt;math&amp;gt;z_1+z_2+\cdots+z_n=k&amp;lt;/math&amp;gt;, which is the number of weak &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, which we have seen is &amp;lt;math&amp;gt;{n+k-1\choose n-1}={n+k-1\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
There is a direct combinatorial proof that &amp;lt;math&amp;gt;\left({n\choose k}\right)={n+k-1\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Given a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multiset &amp;lt;math&amp;gt;0\le a_0\le a_1\le\cdots\le a_{k-1}\le n-1&amp;lt;/math&amp;gt; on &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt;, then defining &amp;lt;math&amp;gt;b_i=a_i+i&amp;lt;/math&amp;gt;, we see that &amp;lt;math&amp;gt;\{b_0,b_1,\ldots,b_{k-1}\}&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset of &amp;lt;math&amp;gt;[n+k-1]&amp;lt;/math&amp;gt;. Conversely, given a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset &amp;lt;math&amp;gt;0\le b_0\le b_1\le\cdots\le b_{k-1}\le n+k-2&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;[n+k-1]&amp;lt;/math&amp;gt;, then defining &amp;lt;math&amp;gt;a_i=b_i-i&amp;lt;/math&amp;gt;, we have that &amp;lt;math&amp;gt;\{b_0,b_1,\ldots,b_{k-1}\}&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multiset on &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt;. Therefore, we have a bijection between &amp;lt;math&amp;gt;\left({[n]\choose k}\right)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;{[n+k-1]\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Multinomial coefficients ===&lt;br /&gt;
&lt;br /&gt;
== Permutations and Partitions ==&lt;br /&gt;
&lt;br /&gt;
== The twelvfold way ==&lt;br /&gt;
We consider a very fundamental counting framework: counting functions &amp;lt;math&amp;gt;f:N\rightarrow M&amp;lt;/math&amp;gt;. We can define different counting problems according to the types of mapping (1-1, on-to, arbitrary), and the types of the domain and the range (distinguishable, indistinguishable).&lt;br /&gt;
* Distinguishability of set:&lt;br /&gt;
* Types of mapping:&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot;  cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;10&amp;quot; rules=&amp;quot;all&amp;quot;  style=&amp;quot;margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Elements of &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt;&lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Elements of &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; &lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Any &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; &lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Injective (1-1) &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; &lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Surjective (on-to) &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;distinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;distinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;m^n\,&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\left(m\right)_n&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;m!S(n, m)\,&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;indistinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;distinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\left({m\choose n}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;|&amp;lt;math&amp;gt;{m\choose n}&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;|&amp;lt;math&amp;gt;\left({m\choose n-m}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;distinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;indistinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\sum_{k=1}^m S(n,k)&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\begin{cases}1 &amp;amp; \mbox{if }n\le m\\ 0&amp;amp; \mbox{if }n&amp;gt;m\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;S(n,m)\,&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;indistinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;indistinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\sum_{k=1}^m p_k(n)&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\begin{cases}1 &amp;amp; \mbox{if }n\le m\\ 0&amp;amp; \mbox{if }n&amp;gt;m\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;p_m(n)\,&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot;  cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;10&amp;quot; rules=&amp;quot;all&amp;quot;  style=&amp;quot;margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | balls per bin&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | unrestricted &lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | ≤ 1&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | ≥ 1&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; labeled balls, &amp;lt;br&amp;gt;&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; labeled bins&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-tuples &amp;lt;br&amp;gt;of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; things&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-permutations &amp;lt;br&amp;gt;of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; things&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partition of &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt; into &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; ordered parts&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; unlabeled balls, &amp;lt;br&amp;gt;&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; labeled bins&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-combinations of &amp;lt;math&amp;gt;[m]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;with repetitions&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-combinations of &amp;lt;math&amp;gt;[m]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt; without repetitions&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; labeled balls, &amp;lt;br&amp;gt;&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; unlabeled bins&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partitions of &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;\le m&amp;lt;/math&amp;gt; parts&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; pigeons &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; holes&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partitions of &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;\le m&amp;lt;/math&amp;gt; parts&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; unlabeled balls, &amp;lt;br&amp;gt;&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; unlabeled bins&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partitions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;\le m&amp;lt;/math&amp;gt; parts&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; pigeons &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; holes&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partitions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; parts&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
* &#039;&#039;Stanley,&#039;&#039; Enumerative Combinatorics, Volume 1, Chapter 1.&lt;/div&gt;</summary>
		<author><name>0:0:0:0:0:0:0:1</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Basic_enumeration&amp;diff=2889</id>
		<title>Combinatorics (Fall 2010)/Basic enumeration</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Basic_enumeration&amp;diff=2889"/>
		<updated>2010-07-10T07:18:17Z</updated>

		<summary type="html">&lt;p&gt;0:0:0:0:0:0:0:1: /* Subsets */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Counting Problems ==&lt;br /&gt;
&lt;br /&gt;
== Sets and Multisets ==&lt;br /&gt;
=== Subsets ===&lt;br /&gt;
We want to count the number of subsets of a set.&lt;br /&gt;
&lt;br /&gt;
Let&amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set, or &#039;&#039;&#039;&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set&#039;&#039;&#039; for short. &lt;br /&gt;
Let &amp;lt;math&amp;gt;2^S=\{T\mid T\subset S\}&amp;lt;/math&amp;gt; denote the set of all subset of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;. &amp;lt;math&amp;gt;2^S&amp;lt;/math&amp;gt; is called the &#039;&#039;&#039;power set&#039;&#039;&#039; of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We give a combinatorial proof that &amp;lt;math&amp;gt;|2^S|=2^n&amp;lt;/math&amp;gt;. We observe that every subset &amp;lt;math&amp;gt;T\in 2^S&amp;lt;/math&amp;gt; corresponds to a unique bit-vector &amp;lt;math&amp;gt;v\in\{0,1\}^S&amp;lt;/math&amp;gt;, such that each bit &amp;lt;math&amp;gt;v_i&amp;lt;/math&amp;gt; indicates whether &amp;lt;math&amp;gt;x_i\in S&amp;lt;/math&amp;gt;. Formally, define a map &amp;lt;math&amp;gt;\phi:2^S\rightarrow\{0,1\}^n&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;\phi(T)=(v_1,v_2,\ldots,v_n)&amp;lt;/math&amp;gt;, where&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
v_i=\begin{cases}&lt;br /&gt;
1 &amp;amp; \mbox{if }x_i\in T\\&lt;br /&gt;
0 &amp;amp; \mbox{if }x_i\not\in T.&lt;br /&gt;
\end{cases}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The map &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; is a &#039;&#039;&#039;bijection&#039;&#039;&#039; (a 1-1 correspondence). The proof that &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; is a bijection is left as an exercise.&lt;br /&gt;
&lt;br /&gt;
Since there is a bijection between &amp;lt;math&amp;gt;2^S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\{0,1\}^n&amp;lt;/math&amp;gt;, it holds that &amp;lt;math&amp;gt;|2^S|=|\{0,1\}^n|=2^n\,&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Here we apply &#039;&#039;&amp;quot;the rule of bijection&amp;quot;&#039;&#039;.&lt;br /&gt;
*&#039;&#039;&#039;The rule of bijection&#039;&#039;&#039;: if there exists a bijection between finite sets &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;, then &amp;lt;math&amp;gt;|P|=|Q|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we know that &amp;lt;math&amp;gt;|\{0,1\}^n|=2^n\,&amp;lt;/math&amp;gt;? We use &#039;&#039;&amp;quot;the rule of product&amp;quot;&#039;&#039;.&lt;br /&gt;
*&#039;&#039;&#039;The rule of product&#039;&#039;&#039;: for any finite sets &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;, the cardinality of the Cartesian product &amp;lt;math&amp;gt;|P\times Q|=|P|\cdot|Q|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To count the size of &amp;lt;math&amp;gt;\{0,1\}^n\,&amp;lt;/math&amp;gt;, we write &amp;lt;math&amp;gt;\{0,1\}^n=\{0,1\}\times\{0,1\}^{n-1}&amp;lt;/math&amp;gt;, thus &amp;lt;math&amp;gt;|\{0,1\}^n|=2|\{0,1\}^{n-1}|\,&amp;lt;/math&amp;gt;. Solving the recursion, we have that &amp;lt;math&amp;gt;|\{0,1\}^n|=2^n\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are two elements of the proof:&lt;br /&gt;
* Find a 1-1 correspondence between subsets of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set and &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-bit vectors.&lt;br /&gt;
: An application of this in Computer Science is that we can use bit-array as a data structure for sets: any set defined over a &#039;&#039;&#039;universe&#039;&#039;&#039; &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; can be represented by an array of &amp;lt;math&amp;gt;|U|&amp;lt;/math&amp;gt; bits.&lt;br /&gt;
* The rule of bijection: if there is a 1-1 correspondence between two sets, then their cardinalities are the same.&lt;br /&gt;
&lt;br /&gt;
Many counting problems are solved by establishing a bijection between the set to be counted and some easy-to-count set. This kind of proofs are usually called (non-rigorously) &#039;&#039;&#039;combinatorial proofs&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
We give an alternative proof that &amp;lt;math&amp;gt;|2^S|=2^n&amp;lt;/math&amp;gt;. The proof needs another basic counting rule:  &#039;&#039;&#039;&amp;quot;the rule of sum&amp;quot;&#039;&#039;&#039;.&lt;br /&gt;
*&#039;&#039;&#039;The rule of sum&#039;&#039;&#039;: for any &#039;&#039;&#039;&#039;&#039;disjoint&#039;&#039;&#039;&#039;&#039; finite sets &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;, the cardinality of the union &amp;lt;math&amp;gt;|P\cup Q|=|P|+|Q|&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Define the function &amp;lt;math&amp;gt;f(n)=|2^{S_n}|&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;S_n=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; is an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. Our goal is to compute &amp;lt;math&amp;gt;f(n)&amp;lt;/math&amp;gt;. We prove the following recursion for &amp;lt;math&amp;gt;f(n)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma|&lt;br /&gt;
:&amp;lt;math&amp;gt;f(n)=2f(n-1)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Fix an element &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; be the set of subsets of &amp;lt;math&amp;gt;S_n&amp;lt;/math&amp;gt; that contain &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt; and let &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; be the set of subsets of &amp;lt;math&amp;gt;S_n&amp;lt;/math&amp;gt; that do not contain &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt;. It is obvious that &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; are disjoint (i.e. &amp;lt;math&amp;gt;U\cap V=\emptyset&amp;lt;/math&amp;gt;) and &amp;lt;math&amp;gt;2^{S_n}=U\cup V&amp;lt;/math&amp;gt;, because any subset of &amp;lt;math&amp;gt;S_n&amp;lt;/math&amp;gt; either contains &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt; or does not contain &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt; but not both.  &lt;br /&gt;
&lt;br /&gt;
Applying the rule of sum, &lt;br /&gt;
:&amp;lt;math&amp;gt;f(n)=|U\cup V|=|U|+|V|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The next observation is that &amp;lt;math&amp;gt;|U|=|V|=f(n-1)&amp;lt;/math&amp;gt;, because &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; is exactly the &amp;lt;math&amp;gt;2^{S_{n-1}}&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; is the set resulting from add &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt; to every member of &amp;lt;math&amp;gt;2^{S_{n-1}}&amp;lt;/math&amp;gt;. Therefore, &lt;br /&gt;
:&amp;lt;math&amp;gt;f(n)=|U|+|V|=f(n-1)+f(n-1)=2f(n-1)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
The elementary case &amp;lt;math&amp;gt;f(0)=1&amp;lt;/math&amp;gt;, because &amp;lt;math&amp;gt;\emptyset&amp;lt;/math&amp;gt; has only one subset &amp;lt;math&amp;gt;\emptyset&amp;lt;/math&amp;gt;. Solving the recursion, we have that &amp;lt;math&amp;gt;|2^S|=f(n)=2^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Subsets of fixed size ===&lt;br /&gt;
We then count the number of subsets of fixed size of a set. Again, let &amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. We define &amp;lt;math&amp;gt;{S\choose k}&amp;lt;/math&amp;gt; to be the set of all &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-elements subsets (or &#039;&#039;&#039;&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subsets&#039;&#039;&#039;) of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;. Formally, &amp;lt;math&amp;gt;{S\choose k}=\{T\subseteq S\mid |T|=k\}&amp;lt;/math&amp;gt;. The set &amp;lt;math&amp;gt;{S\choose k}&amp;lt;/math&amp;gt; is sometimes called the &#039;&#039;&#039;&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-uniform&#039;&#039;&#039; of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We denote that &amp;lt;math&amp;gt;{n\choose k}=\left|{S\choose k}\right|&amp;lt;/math&amp;gt;. The notation &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; is read &amp;quot;&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; choose &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:&amp;lt;math&amp;gt;{n\choose k}=\frac{n(n-1)\cdots(n-k+1)}{k(k-1)\cdots 1}=\frac{n!}{k!(n-k)!}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
The number of &#039;&#039;&#039;ordered&#039;&#039;&#039; &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subsets of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set is &amp;lt;math&amp;gt;n(n-1)\cdots(n-k+1)&amp;lt;/math&amp;gt;. Every &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset has &amp;lt;math&amp;gt;k!=k(k-1)\cdots1&amp;lt;/math&amp;gt; ways to order it.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
;Some notations&lt;br /&gt;
* &amp;lt;math&amp;gt;n!&amp;lt;/math&amp;gt;, read &amp;quot;&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; factorial&amp;quot;, is defined as that &amp;lt;math&amp;gt;n!=n(n-1)(n-2)\cdots 1&amp;lt;/math&amp;gt;, with the convention that &amp;lt;math&amp;gt;0!=1&amp;lt;/math&amp;gt;.&lt;br /&gt;
* &amp;lt;math&amp;gt;n(n-1)\cdots(n-k+1)=\frac{n!}{(n-k)!}&amp;lt;/math&amp;gt; is usually denoted as &amp;lt;math&amp;gt;(n)_k\,&amp;lt;/math&amp;gt;, read &amp;quot;&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; lower factorial &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;binomial coefficient&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Proposition|&lt;br /&gt;
# &amp;lt;math&amp;gt;{n\choose k}={n\choose n-k}&amp;lt;/math&amp;gt;;&lt;br /&gt;
# &amp;lt;math&amp;gt;\sum_{k=0}^n {n\choose k}=2^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
1. We give two proofs for the first equation:&lt;br /&gt;
:(1) (numerical proof)&lt;br /&gt;
::&amp;lt;math&amp;gt;{n\choose k}=\frac{n!}{k!(n-k)!}={n\choose n-k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:(2) (combinatorial proof)&lt;br /&gt;
::Choosing &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; elements from an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set is equivalent to choosing the &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; elements to leave out. Formally, every &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset &amp;lt;math&amp;gt;T\in{S\choose k}&amp;lt;/math&amp;gt; is uniquely specified by its complement &amp;lt;math&amp;gt;S\setminus T\in {S\choose n-k}&amp;lt;/math&amp;gt;, and the same holds for &amp;lt;math&amp;gt;(n-k)&amp;lt;/math&amp;gt;-subsets, thus we have a bijection between &amp;lt;math&amp;gt;{S\choose k}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;{S\choose n-k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
2. The second equation can also be proved in different ways, but the combinatorial proof is much easier. For an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;, it is obvious that we can enumerate all subsets of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; by enumerating &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subsets for every possible size &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, i.e. it holds that&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
2^S=\bigcup_{k=0}^n{S\choose k}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
For different &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;{S\choose k}&amp;lt;/math&amp;gt; are obviously disjoint. By the rule of sum,&lt;br /&gt;
:&amp;lt;math&amp;gt;2^n=|2^S|=\left|\bigcup_{k=0}^n{S\choose k}\right|=\sum_{k=0}^n\left|{S\choose k}\right|=\sum_{k=0}^n {n\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; is called binomial coefficient for a reason. A binomial is a polynomial with two terms (&amp;quot;poly-&amp;quot; means many, and &amp;quot;bi-&amp;quot; means two, like in &amp;quot;binary&amp;quot;, &amp;quot;bipartite&amp;quot;, etc). The following celebrated &#039;&#039;&#039;Binomial Theorem&#039;&#039;&#039; states that if a power of a binomial is expanded, the coefficients in the resulting polynomial are the binomial coefficients.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Binomial theorem)|&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x)^n=\sum_{k=0}^n{n\choose k}x^k&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Write &amp;lt;math&amp;gt;(1+x)^n&amp;lt;/math&amp;gt; as the product of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; factors&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x)(1+x)\cdots (1+x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
The term &amp;lt;math&amp;gt;x^k&amp;lt;/math&amp;gt; is obtained by choosing &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; factors and 1 from the rest &amp;lt;math&amp;gt;(n-k)&amp;lt;/math&amp;gt; factors. There are &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; ways of choosing these &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; factors, so the coefficient of &amp;lt;math&amp;gt;x^k&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The following proposition has an easy proof due to the binomial theorem.&lt;br /&gt;
{{Theorem| Proposition|&lt;br /&gt;
:For &amp;lt;math&amp;gt;n&amp;gt;0&amp;lt;/math&amp;gt;, the numbers of subsets of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set of even and of odd cardinality are equal.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Set &amp;lt;math&amp;gt;x=-1&amp;lt;/math&amp;gt; in the binomial theorem.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
0=(1-1)^n=\sum_{k=0}^n{n\choose k}(-1)^k=\sum_{\overset{0\le k\le n}{k \text{ even}}}{n\choose k}-\sum_{\overset{0\le k\le n}{k \text{ odd}}}{n\choose k},&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
therefore&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{\overset{0\le k\le n}{k \text{ even}}}{n\choose k}=\sum_{\overset{0\le k\le n}{k \text{ odd}}}{n\choose k}.&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
For counting problems, what we care about are &#039;&#039;numbers&#039;&#039;. In the binomial theorem, a formal &#039;&#039;variable&#039;&#039; &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is introduced. It looks having nothing to do with our problem, but turns out to be very useful. This idea of introducing a formal variable is the basic idea of some advanced counting techniques, which will be discussed in future classes.&lt;br /&gt;
&lt;br /&gt;
=== Compositions of an integer ===&lt;br /&gt;
A &#039;&#039;&#039;composition&#039;&#039;&#039; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is an expression of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; as an &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&#039;&#039;ordered&#039;&#039;&amp;lt;/font&amp;gt; sum of &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&#039;&#039;positive&#039;&#039;&amp;lt;/font&amp;gt; integers. A &#039;&#039;&#039;&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition&#039;&#039;&#039; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is a composition of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with exactly &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; positive summands. &lt;br /&gt;
&lt;br /&gt;
Formally, a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-tuple &amp;lt;math&amp;gt;(a_1,a_2,\ldots,a_k)\in\{1,2,\ldots,n\}^k&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;a_1+a_2+\cdots+a_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Suppose we have &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; identical balls in a line. A &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition partitions these &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; balls into &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; &#039;&#039;nonempty&#039;&#039; sets, illustrated as follows.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{array}{c|cc|c|c|ccc|cc}&lt;br /&gt;
\bigcirc \,&amp;amp;\, \bigcirc \,&amp;amp; \bigcirc \,&amp;amp;\, \bigcirc \,&amp;amp;\, \bigcirc \,&amp;amp;\, \bigcirc &amp;amp;\, \bigcirc &amp;amp;\, \bigcirc \,&amp;amp;\, \bigcirc \,&amp;amp; \bigcirc&lt;br /&gt;
\end{array}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; equals the number of ways we put &amp;lt;math&amp;gt;k-1&amp;lt;/math&amp;gt; bars &amp;quot;&amp;lt;math&amp;gt;|&amp;lt;/math&amp;gt;&amp;quot; into &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt; slots &amp;quot;&amp;lt;math&amp;gt;\sqcup&amp;lt;/math&amp;gt;&amp;quot;, where each slot has at most one bar (because all the summands &amp;lt;math&amp;gt;a_i&amp;gt;0&amp;lt;/math&amp;gt;):&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
which is equal to the number of ways of choosing &amp;lt;math&amp;gt;k-1&amp;lt;/math&amp;gt; slots out of &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt; slots, which is &amp;lt;math&amp;gt;{n-1\choose k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This graphic argument can be expressed as a formal proof. We construct a bijection between the set of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;{\{1,2,\ldots,n-1\}\choose k-1}&amp;lt;/math&amp;gt; as follows. &lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; be a mapping that given a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition &amp;lt;math&amp;gt;(a_1,a_2,\ldots,a_k)&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\phi((a_1,a_2,\ldots,a_k))&lt;br /&gt;
&amp;amp;=\{a_1,\,\,a_1+a_2,\,\,a_1+a_2+a_3,\,\,\ldots,\,\,a_1+a_2+\cdots+a_{k-1}\}\\&lt;br /&gt;
&amp;amp;=\left\{\sum_{i=1}^ja_i\,\,\bigg|\,\, 1\le j&amp;lt;k\right\}.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; maps every &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition to a &amp;lt;math&amp;gt;(k-1)&amp;lt;/math&amp;gt;-subset of &amp;lt;math&amp;gt;\{1,2,\ldots,n-1\}&amp;lt;/math&amp;gt;. It is easy to verify that &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; is a bijection, thus the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;{n-1\choose k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
----&lt;br /&gt;
The number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is equal to the number of &#039;&#039;positive&#039;&#039; integer solutions to &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;. This suggests us to relax the constraint and count the number of &#039;&#039;nonnegative&#039;&#039; integer solutions to &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;. We call such a solution a &#039;&#039;&#039;weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition&#039;&#039;&#039; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Formally, a weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is a tuple &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)\in[n+1]^k&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Given a weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, if we set &amp;lt;math&amp;gt;y_i=x_i+1&amp;lt;/math&amp;gt; for every &amp;lt;math&amp;gt;1\le i\le k&amp;lt;/math&amp;gt;, then &amp;lt;math&amp;gt;y_i&amp;gt;0&amp;lt;/math&amp;gt; and &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
y_1+y_2+\cdots +y_k&lt;br /&gt;
&amp;amp;=(x_1+1)+(x_2+1)+\cdots+(x_k+1)&amp;amp;=n+k,&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
i.e., &amp;lt;math&amp;gt;(y_1,y_2,\ldots,y_k)&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition of &amp;lt;math&amp;gt;n+k&amp;lt;/math&amp;gt;. It is easy to see that it defines a bijection between weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n+k&amp;lt;/math&amp;gt;. Therefore, the number of weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;{n+k-1\choose k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
----&lt;br /&gt;
We now count the number of nonnegative integer solutions to &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k\le n&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;x_{k+1}=n-(x_1+x_2+\cdots+x_k)&amp;lt;/math&amp;gt;. Then &amp;lt;math&amp;gt;x_{k+1}\ge 0&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_1+x_2+\ldots+x_k+x_{k+1}=n&amp;lt;/math&amp;gt;. &lt;br /&gt;
The problem is transformed to that counting the number of nonnegative integer solutions to the above equation. The answer is &amp;lt;math&amp;gt;{n+k\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Multisets ===&lt;br /&gt;
A &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is sometimes called a &#039;&#039;&#039;&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-combination of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; without repetitions&#039;&#039;&#039;. This suggests the problem of counting the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-combinations of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; &#039;&#039;&#039;&#039;&#039;with repetitions&#039;&#039;&#039;&#039;&#039;; that is, we choose &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; elements of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;, disregarding order and allowing repeated elements. &lt;br /&gt;
&lt;br /&gt;
;Example&lt;br /&gt;
:&amp;lt;math&amp;gt;S=\{1,2,3,4\}&amp;lt;/math&amp;gt;. All &amp;lt;math&amp;gt;3&amp;lt;/math&amp;gt;-combination without repetitions are &lt;br /&gt;
::&amp;lt;math&amp;gt;\{1,2,3\},\{1,2,4\},\{1,3,4\},\{2,3,4\}\,&amp;lt;/math&amp;gt;. &lt;br /&gt;
:Allowing repetitions, we also include the following 3-combinations:&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
&amp;amp;\{1,1,1\},\{1,1,2\},\{1,1,3\},\{1,1,4\},\{1,2,2\},\{1,3,3\},\{1,4,4\},\\&lt;br /&gt;
&amp;amp;\{2,2,2\},\{2,2,3\},\{2,2,4\},\{2,3,3\},\{2,4,4\},\\&lt;br /&gt;
&amp;amp;\{3,3,3\},\{3,3,4\},\{3,4,4\}\\&lt;br /&gt;
&amp;amp;\{4,4,4\}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Combinations with repetitions can be formally defined as &#039;&#039;&#039;multisets&#039;&#039;&#039;. A multiset is a set with repeated elements. Formally, a multiset &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; on a set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is a function &amp;lt;math&amp;gt;m:S\rightarrow \mathbb{N}&amp;lt;/math&amp;gt;. For any element &amp;lt;math&amp;gt;x\in S&amp;lt;/math&amp;gt;, the integer &amp;lt;math&amp;gt;m(x)\ge 0&amp;lt;/math&amp;gt; is the number of repetitions of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt;, called the &#039;&#039;&#039;multiplicity&#039;&#039;&#039; of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;. The sum of multiplicities &amp;lt;math&amp;gt;\sum_{x\in S}m(x)&amp;lt;/math&amp;gt; is called the &#039;&#039;&#039;cardinality&#039;&#039;&#039; of &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; and is denoted as &amp;lt;math&amp;gt;|M|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multiset on a set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is a multiset &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|M|=k&amp;lt;/math&amp;gt;. It is obvious that a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-combination of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; with repetition is simply a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multiset on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The set of all &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multisets on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is denoted &amp;lt;math&amp;gt;\left({S\choose k}\right)&amp;lt;/math&amp;gt;. Assuming that &amp;lt;math&amp;gt;n=|S|&amp;lt;/math&amp;gt;, denote &amp;lt;math&amp;gt;\left({n\choose k}\right)=\left|\left({S\choose k}\right)\right|&amp;lt;/math&amp;gt;, which is the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-combinations of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set with repetitions.&lt;br /&gt;
&lt;br /&gt;
Believe it or not: we have already evaluated the number  &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;z_i=m(x_i)&amp;lt;/math&amp;gt;, then &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt; is the number of nonnegative integer solutions to &amp;lt;math&amp;gt;z_1+z_2+\cdots+z_n=k&amp;lt;/math&amp;gt;, which is the number of weak &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, which we have seen is &amp;lt;math&amp;gt;{n+k-1\choose n-1}={n+k-1\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
There is a direct combinatorial proof that &amp;lt;math&amp;gt;\left({n\choose k}\right)={n+k-1\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Given a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multiset &amp;lt;math&amp;gt;0\le a_0\le a_1\le\cdots\le a_{k-1}\le n-1&amp;lt;/math&amp;gt; on &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt;, then defining &amp;lt;math&amp;gt;b_i=a_i+i&amp;lt;/math&amp;gt;, we see that &amp;lt;math&amp;gt;\{b_0,b_1,\ldots,b_{k-1}\}&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset of &amp;lt;math&amp;gt;[n+k-1]&amp;lt;/math&amp;gt;. Conversely, given a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset &amp;lt;math&amp;gt;0\le b_0\le b_1\le\cdots\le b_{k-1}\le n+k-2&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;[n+k-1]&amp;lt;/math&amp;gt;, then defining &amp;lt;math&amp;gt;a_i=b_i-i&amp;lt;/math&amp;gt;, we have that &amp;lt;math&amp;gt;\{b_0,b_1,\ldots,b_{k-1}\}&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multiset on &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt;. Therefore, we have a bijection between &amp;lt;math&amp;gt;\left({[n]\choose k}\right)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;{[n+k-1]\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Multinomial coefficients ===&lt;br /&gt;
&lt;br /&gt;
== Permutations and Partitions ==&lt;br /&gt;
&lt;br /&gt;
== The twelvfold way ==&lt;br /&gt;
We consider a very fundamental counting framework: counting functions &amp;lt;math&amp;gt;f:N\rightarrow M&amp;lt;/math&amp;gt;. We can define different counting problems according to the types of mapping (1-1, on-to, arbitrary), and the types of the domain and the range (distinguishable, indistinguishable).&lt;br /&gt;
* Distinguishability of set:&lt;br /&gt;
* Types of mapping:&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot;  cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;10&amp;quot; rules=&amp;quot;all&amp;quot;  style=&amp;quot;margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Elements of &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt;&lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Elements of &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; &lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Any &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; &lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Injective (1-1) &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; &lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Surjective (on-to) &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;distinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;distinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;m^n\,&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\left(m\right)_n&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;m!S(n, m)\,&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;indistinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;distinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\left({m\choose n}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;|&amp;lt;math&amp;gt;{m\choose n}&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;|&amp;lt;math&amp;gt;\left({m\choose n-m}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;distinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;indistinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\sum_{k=1}^m S(n,k)&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\begin{cases}1 &amp;amp; \mbox{if }n\le m\\ 0&amp;amp; \mbox{if }n&amp;gt;m\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;S(n,m)\,&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;indistinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;indistinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\sum_{k=1}^m p_k(n)&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\begin{cases}1 &amp;amp; \mbox{if }n\le m\\ 0&amp;amp; \mbox{if }n&amp;gt;m\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;p_m(n)\,&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot;  cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;10&amp;quot; rules=&amp;quot;all&amp;quot;  style=&amp;quot;margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | balls per bin&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | unrestricted &lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | ≤ 1&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | ≥ 1&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; labeled balls, &amp;lt;br&amp;gt;&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; labeled bins&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-tuples &amp;lt;br&amp;gt;of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; things&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-permutations &amp;lt;br&amp;gt;of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; things&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partition of &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt; into &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; ordered parts&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; unlabeled balls, &amp;lt;br&amp;gt;&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; labeled bins&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-combinations of &amp;lt;math&amp;gt;[m]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;with repetitions&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-combinations of &amp;lt;math&amp;gt;[m]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt; without repetitions&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; labeled balls, &amp;lt;br&amp;gt;&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; unlabeled bins&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partitions of &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;\le m&amp;lt;/math&amp;gt; parts&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; pigeons &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; holes&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partitions of &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;\le m&amp;lt;/math&amp;gt; parts&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; unlabeled balls, &amp;lt;br&amp;gt;&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; unlabeled bins&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partitions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;\le m&amp;lt;/math&amp;gt; parts&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; pigeons &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; holes&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partitions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; parts&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
* &#039;&#039;Stanley,&#039;&#039; Enumerative Combinatorics, Volume 1, Chapter 1.&lt;/div&gt;</summary>
		<author><name>0:0:0:0:0:0:0:1</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Basic_enumeration&amp;diff=2888</id>
		<title>Combinatorics (Fall 2010)/Basic enumeration</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Basic_enumeration&amp;diff=2888"/>
		<updated>2010-07-10T07:15:15Z</updated>

		<summary type="html">&lt;p&gt;0:0:0:0:0:0:0:1: /* Subsets */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Counting Problems ==&lt;br /&gt;
&lt;br /&gt;
== Sets and Multisets ==&lt;br /&gt;
=== Subsets ===&lt;br /&gt;
We want to count the number of subsets of a set.&lt;br /&gt;
&lt;br /&gt;
Let&amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set, or &#039;&#039;&#039;&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set&#039;&#039;&#039; for short. &lt;br /&gt;
Let &amp;lt;math&amp;gt;2^S=\{T\mid T\subset S\}&amp;lt;/math&amp;gt; denote the set of all subset of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;. &amp;lt;math&amp;gt;2^S&amp;lt;/math&amp;gt; is called the &#039;&#039;&#039;power set&#039;&#039;&#039; of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We give a combinatorial proof that &amp;lt;math&amp;gt;|2^S|=2^n&amp;lt;/math&amp;gt;. We observe that every subset &amp;lt;math&amp;gt;T\in 2^S&amp;lt;/math&amp;gt; corresponds to a unique bit-vector &amp;lt;math&amp;gt;v\in\{0,1\}^S&amp;lt;/math&amp;gt;, such that each bit &amp;lt;math&amp;gt;v_i&amp;lt;/math&amp;gt; indicates whether &amp;lt;math&amp;gt;x_i\in S&amp;lt;/math&amp;gt;. Formally, define a map &amp;lt;math&amp;gt;\phi:2^S\rightarrow\{0,1\}^n&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;\phi(T)=(v_1,v_2,\ldots,v_n)&amp;lt;/math&amp;gt;, where&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
v_i=\begin{cases}&lt;br /&gt;
1 &amp;amp; \mbox{if }x_i\in T\\&lt;br /&gt;
0 &amp;amp; \mbox{if }x_i\not\in T.&lt;br /&gt;
\end{cases}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The map &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; is a &#039;&#039;&#039;bijection&#039;&#039;&#039; (a 1-1 correspondence). The proof that &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; is a bijection is left as an exercise.&lt;br /&gt;
&lt;br /&gt;
Since there is a bijection between &amp;lt;math&amp;gt;2^S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\{0,1\}^n&amp;lt;/math&amp;gt;, it holds that &amp;lt;math&amp;gt;|2^S|=|\{0,1\}^n|=2^n\,&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Here we apply &#039;&#039;&amp;quot;the rule of bijection&amp;quot;&#039;&#039;.&lt;br /&gt;
*&#039;&#039;&#039;The rule of bijection&#039;&#039;&#039;: if there exists a bijection between finite sets &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;, then &amp;lt;math&amp;gt;|P|=|Q|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we know that &amp;lt;math&amp;gt;|\{0,1\}^n|=2^n\,&amp;lt;/math&amp;gt;? We use &#039;&#039;&amp;quot;the rule of product&amp;quot;&#039;&#039;.&lt;br /&gt;
*&#039;&#039;&#039;The rule of product&#039;&#039;&#039;: for any finite sets &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;, the cardinality of the Cartesian product &amp;lt;math&amp;gt;|P\times Q|=|P|\cdot|Q|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To count the size of &amp;lt;math&amp;gt;\{0,1\}^n\,&amp;lt;/math&amp;gt;, we write &amp;lt;math&amp;gt;\{0,1\}^n=\{0,1\}\times\{0,1\}^{n-1}&amp;lt;/math&amp;gt;, thus &amp;lt;math&amp;gt;|\{0,1\}^n|=2|\{0,1\}^{n-1}|\,&amp;lt;/math&amp;gt;. Solving the recursion, we have that &amp;lt;math&amp;gt;|\{0,1\}^n|=2^n\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are two elements of the proof:&lt;br /&gt;
* Find a 1-1 correspondence between subsets of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set and &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-bit vectors.&lt;br /&gt;
: An application of this in Computer Science is that we can use bit-array as a data structure for sets: any set defined over a &#039;&#039;&#039;universe&#039;&#039;&#039; &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; can be represented by an array of &amp;lt;math&amp;gt;|U|&amp;lt;/math&amp;gt; bits.&lt;br /&gt;
* The rule of bijection: if there is a 1-1 correspondence between two sets, then their cardinalities are the same.&lt;br /&gt;
&lt;br /&gt;
Many counting problems are solved by establishing a bijection between the set to be counted and some easy-to-count set. This kind of proofs are usually called (non-rigorously) &#039;&#039;&#039;combinatorial proofs&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
We give an alternative proof that &amp;lt;math&amp;gt;|2^S|=2^n&amp;lt;/math&amp;gt;. Define the function &amp;lt;math&amp;gt;f(n)=|2^{S_n}|&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;S_n=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; is an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. Our goal is to compute &amp;lt;math&amp;gt;f(n)&amp;lt;/math&amp;gt;. We prove the following recursion for &amp;lt;math&amp;gt;f(n)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma|&lt;br /&gt;
:&amp;lt;math&amp;gt;f(n)=2f(n-1)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Fix an element &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; be the set of subsets of &amp;lt;math&amp;gt;S_n&amp;lt;/math&amp;gt; that contain &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt; and let &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; be the set of subsets of &amp;lt;math&amp;gt;S_n&amp;lt;/math&amp;gt; that do not contain &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt;. It is obvious that &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; are disjoint (i.e. &amp;lt;math&amp;gt;U\cap V=\emptyset&amp;lt;/math&amp;gt;) and &amp;lt;math&amp;gt;2^{S_n}=U\cup V&amp;lt;/math&amp;gt;, because any subset of &amp;lt;math&amp;gt;S_n&amp;lt;/math&amp;gt; either contains &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt; or does not contain &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt; but not both.  &lt;br /&gt;
&lt;br /&gt;
We apply &#039;&#039;&#039;&amp;quot;the rule of sum&amp;quot;&#039;&#039;&#039;: for any &#039;&#039;&#039;&#039;&#039;disjoint&#039;&#039;&#039;&#039;&#039; finite sets &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;, the cardinality of the union &amp;lt;math&amp;gt;|P\cup Q|=|P|+|Q|&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Therefore, &lt;br /&gt;
:&amp;lt;math&amp;gt;f(n)=|U\cup V|=|U|+|V|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The next observation is that &amp;lt;math&amp;gt;|U|=|V|=f(n-1)&amp;lt;/math&amp;gt;, because &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; is exactly the &amp;lt;math&amp;gt;2^{S_{n-1}}&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; is the set resulting from add &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt; to every member of &amp;lt;math&amp;gt;2^{S_{n-1}}&amp;lt;/math&amp;gt;. Therefore, &lt;br /&gt;
:&amp;lt;math&amp;gt;f(n)=|U|+|V|=f(n-1)+f(n-1)=2f(n-1)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
The elementary case &amp;lt;math&amp;gt;f(0)=1&amp;lt;/math&amp;gt;, because &amp;lt;math&amp;gt;\emptyset&amp;lt;/math&amp;gt; has only one subset &amp;lt;math&amp;gt;\emptyset&amp;lt;/math&amp;gt;. Solving the recursion, we have that &amp;lt;math&amp;gt;|2^S|=f(n)=2^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Subsets of fixed size ===&lt;br /&gt;
We then count the number of subsets of fixed size of a set. Again, let &amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. We define &amp;lt;math&amp;gt;{S\choose k}&amp;lt;/math&amp;gt; to be the set of all &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-elements subsets (or &#039;&#039;&#039;&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subsets&#039;&#039;&#039;) of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;. Formally, &amp;lt;math&amp;gt;{S\choose k}=\{T\subseteq S\mid |T|=k\}&amp;lt;/math&amp;gt;. The set &amp;lt;math&amp;gt;{S\choose k}&amp;lt;/math&amp;gt; is sometimes called the &#039;&#039;&#039;&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-uniform&#039;&#039;&#039; of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We denote that &amp;lt;math&amp;gt;{n\choose k}=\left|{S\choose k}\right|&amp;lt;/math&amp;gt;. The notation &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; is read &amp;quot;&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; choose &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:&amp;lt;math&amp;gt;{n\choose k}=\frac{n(n-1)\cdots(n-k+1)}{k(k-1)\cdots 1}=\frac{n!}{k!(n-k)!}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
The number of &#039;&#039;&#039;ordered&#039;&#039;&#039; &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subsets of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set is &amp;lt;math&amp;gt;n(n-1)\cdots(n-k+1)&amp;lt;/math&amp;gt;. Every &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset has &amp;lt;math&amp;gt;k!=k(k-1)\cdots1&amp;lt;/math&amp;gt; ways to order it.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
;Some notations&lt;br /&gt;
* &amp;lt;math&amp;gt;n!&amp;lt;/math&amp;gt;, read &amp;quot;&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; factorial&amp;quot;, is defined as that &amp;lt;math&amp;gt;n!=n(n-1)(n-2)\cdots 1&amp;lt;/math&amp;gt;, with the convention that &amp;lt;math&amp;gt;0!=1&amp;lt;/math&amp;gt;.&lt;br /&gt;
* &amp;lt;math&amp;gt;n(n-1)\cdots(n-k+1)=\frac{n!}{(n-k)!}&amp;lt;/math&amp;gt; is usually denoted as &amp;lt;math&amp;gt;(n)_k\,&amp;lt;/math&amp;gt;, read &amp;quot;&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; lower factorial &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;binomial coefficient&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Proposition|&lt;br /&gt;
# &amp;lt;math&amp;gt;{n\choose k}={n\choose n-k}&amp;lt;/math&amp;gt;;&lt;br /&gt;
# &amp;lt;math&amp;gt;\sum_{k=0}^n {n\choose k}=2^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
1. We give two proofs for the first equation:&lt;br /&gt;
:(1) (numerical proof)&lt;br /&gt;
::&amp;lt;math&amp;gt;{n\choose k}=\frac{n!}{k!(n-k)!}={n\choose n-k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:(2) (combinatorial proof)&lt;br /&gt;
::Choosing &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; elements from an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set is equivalent to choosing the &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; elements to leave out. Formally, every &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset &amp;lt;math&amp;gt;T\in{S\choose k}&amp;lt;/math&amp;gt; is uniquely specified by its complement &amp;lt;math&amp;gt;S\setminus T\in {S\choose n-k}&amp;lt;/math&amp;gt;, and the same holds for &amp;lt;math&amp;gt;(n-k)&amp;lt;/math&amp;gt;-subsets, thus we have a bijection between &amp;lt;math&amp;gt;{S\choose k}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;{S\choose n-k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
2. The second equation can also be proved in different ways, but the combinatorial proof is much easier. For an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;, it is obvious that we can enumerate all subsets of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; by enumerating &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subsets for every possible size &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, i.e. it holds that&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
2^S=\bigcup_{k=0}^n{S\choose k}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
For different &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;{S\choose k}&amp;lt;/math&amp;gt; are obviously disjoint. By the rule of sum,&lt;br /&gt;
:&amp;lt;math&amp;gt;2^n=|2^S|=\left|\bigcup_{k=0}^n{S\choose k}\right|=\sum_{k=0}^n\left|{S\choose k}\right|=\sum_{k=0}^n {n\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; is called binomial coefficient for a reason. A binomial is a polynomial with two terms (&amp;quot;poly-&amp;quot; means many, and &amp;quot;bi-&amp;quot; means two, like in &amp;quot;binary&amp;quot;, &amp;quot;bipartite&amp;quot;, etc). The following celebrated &#039;&#039;&#039;Binomial Theorem&#039;&#039;&#039; states that if a power of a binomial is expanded, the coefficients in the resulting polynomial are the binomial coefficients.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Binomial theorem)|&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x)^n=\sum_{k=0}^n{n\choose k}x^k&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Write &amp;lt;math&amp;gt;(1+x)^n&amp;lt;/math&amp;gt; as the product of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; factors&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x)(1+x)\cdots (1+x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
The term &amp;lt;math&amp;gt;x^k&amp;lt;/math&amp;gt; is obtained by choosing &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; factors and 1 from the rest &amp;lt;math&amp;gt;(n-k)&amp;lt;/math&amp;gt; factors. There are &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; ways of choosing these &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; factors, so the coefficient of &amp;lt;math&amp;gt;x^k&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The following proposition has an easy proof due to the binomial theorem.&lt;br /&gt;
{{Theorem| Proposition|&lt;br /&gt;
:For &amp;lt;math&amp;gt;n&amp;gt;0&amp;lt;/math&amp;gt;, the numbers of subsets of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set of even and of odd cardinality are equal.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Set &amp;lt;math&amp;gt;x=-1&amp;lt;/math&amp;gt; in the binomial theorem.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
0=(1-1)^n=\sum_{k=0}^n{n\choose k}(-1)^k=\sum_{\overset{0\le k\le n}{k \text{ even}}}{n\choose k}-\sum_{\overset{0\le k\le n}{k \text{ odd}}}{n\choose k},&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
therefore&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{\overset{0\le k\le n}{k \text{ even}}}{n\choose k}=\sum_{\overset{0\le k\le n}{k \text{ odd}}}{n\choose k}.&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
For counting problems, what we care about are &#039;&#039;numbers&#039;&#039;. In the binomial theorem, a formal &#039;&#039;variable&#039;&#039; &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is introduced. It looks having nothing to do with our problem, but turns out to be very useful. This idea of introducing a formal variable is the basic idea of some advanced counting techniques, which will be discussed in future classes.&lt;br /&gt;
&lt;br /&gt;
=== Compositions of an integer ===&lt;br /&gt;
A &#039;&#039;&#039;composition&#039;&#039;&#039; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is an expression of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; as an &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&#039;&#039;ordered&#039;&#039;&amp;lt;/font&amp;gt; sum of &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&#039;&#039;positive&#039;&#039;&amp;lt;/font&amp;gt; integers. A &#039;&#039;&#039;&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition&#039;&#039;&#039; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is a composition of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with exactly &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; positive summands. &lt;br /&gt;
&lt;br /&gt;
Formally, a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-tuple &amp;lt;math&amp;gt;(a_1,a_2,\ldots,a_k)\in\{1,2,\ldots,n\}^k&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;a_1+a_2+\cdots+a_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Suppose we have &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; identical balls in a line. A &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition partitions these &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; balls into &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; &#039;&#039;nonempty&#039;&#039; sets, illustrated as follows.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{array}{c|cc|c|c|ccc|cc}&lt;br /&gt;
\bigcirc \,&amp;amp;\, \bigcirc \,&amp;amp; \bigcirc \,&amp;amp;\, \bigcirc \,&amp;amp;\, \bigcirc \,&amp;amp;\, \bigcirc &amp;amp;\, \bigcirc &amp;amp;\, \bigcirc \,&amp;amp;\, \bigcirc \,&amp;amp; \bigcirc&lt;br /&gt;
\end{array}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; equals the number of ways we put &amp;lt;math&amp;gt;k-1&amp;lt;/math&amp;gt; bars &amp;quot;&amp;lt;math&amp;gt;|&amp;lt;/math&amp;gt;&amp;quot; into &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt; slots &amp;quot;&amp;lt;math&amp;gt;\sqcup&amp;lt;/math&amp;gt;&amp;quot;, where each slot has at most one bar (because all the summands &amp;lt;math&amp;gt;a_i&amp;gt;0&amp;lt;/math&amp;gt;):&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
which is equal to the number of ways of choosing &amp;lt;math&amp;gt;k-1&amp;lt;/math&amp;gt; slots out of &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt; slots, which is &amp;lt;math&amp;gt;{n-1\choose k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This graphic argument can be expressed as a formal proof. We construct a bijection between the set of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;{\{1,2,\ldots,n-1\}\choose k-1}&amp;lt;/math&amp;gt; as follows. &lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; be a mapping that given a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition &amp;lt;math&amp;gt;(a_1,a_2,\ldots,a_k)&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\phi((a_1,a_2,\ldots,a_k))&lt;br /&gt;
&amp;amp;=\{a_1,\,\,a_1+a_2,\,\,a_1+a_2+a_3,\,\,\ldots,\,\,a_1+a_2+\cdots+a_{k-1}\}\\&lt;br /&gt;
&amp;amp;=\left\{\sum_{i=1}^ja_i\,\,\bigg|\,\, 1\le j&amp;lt;k\right\}.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; maps every &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition to a &amp;lt;math&amp;gt;(k-1)&amp;lt;/math&amp;gt;-subset of &amp;lt;math&amp;gt;\{1,2,\ldots,n-1\}&amp;lt;/math&amp;gt;. It is easy to verify that &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; is a bijection, thus the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;{n-1\choose k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
----&lt;br /&gt;
The number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is equal to the number of &#039;&#039;positive&#039;&#039; integer solutions to &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;. This suggests us to relax the constraint and count the number of &#039;&#039;nonnegative&#039;&#039; integer solutions to &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;. We call such a solution a &#039;&#039;&#039;weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition&#039;&#039;&#039; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Formally, a weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is a tuple &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)\in[n+1]^k&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Given a weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, if we set &amp;lt;math&amp;gt;y_i=x_i+1&amp;lt;/math&amp;gt; for every &amp;lt;math&amp;gt;1\le i\le k&amp;lt;/math&amp;gt;, then &amp;lt;math&amp;gt;y_i&amp;gt;0&amp;lt;/math&amp;gt; and &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
y_1+y_2+\cdots +y_k&lt;br /&gt;
&amp;amp;=(x_1+1)+(x_2+1)+\cdots+(x_k+1)&amp;amp;=n+k,&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
i.e., &amp;lt;math&amp;gt;(y_1,y_2,\ldots,y_k)&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition of &amp;lt;math&amp;gt;n+k&amp;lt;/math&amp;gt;. It is easy to see that it defines a bijection between weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n+k&amp;lt;/math&amp;gt;. Therefore, the number of weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;{n+k-1\choose k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
----&lt;br /&gt;
We now count the number of nonnegative integer solutions to &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k\le n&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;x_{k+1}=n-(x_1+x_2+\cdots+x_k)&amp;lt;/math&amp;gt;. Then &amp;lt;math&amp;gt;x_{k+1}\ge 0&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_1+x_2+\ldots+x_k+x_{k+1}=n&amp;lt;/math&amp;gt;. &lt;br /&gt;
The problem is transformed to that counting the number of nonnegative integer solutions to the above equation. The answer is &amp;lt;math&amp;gt;{n+k\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Multisets ===&lt;br /&gt;
A &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is sometimes called a &#039;&#039;&#039;&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-combination of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; without repetitions&#039;&#039;&#039;. This suggests the problem of counting the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-combinations of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; &#039;&#039;&#039;&#039;&#039;with repetitions&#039;&#039;&#039;&#039;&#039;; that is, we choose &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; elements of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;, disregarding order and allowing repeated elements. &lt;br /&gt;
&lt;br /&gt;
;Example&lt;br /&gt;
:&amp;lt;math&amp;gt;S=\{1,2,3,4\}&amp;lt;/math&amp;gt;. All &amp;lt;math&amp;gt;3&amp;lt;/math&amp;gt;-combination without repetitions are &lt;br /&gt;
::&amp;lt;math&amp;gt;\{1,2,3\},\{1,2,4\},\{1,3,4\},\{2,3,4\}\,&amp;lt;/math&amp;gt;. &lt;br /&gt;
:Allowing repetitions, we also include the following 3-combinations:&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
&amp;amp;\{1,1,1\},\{1,1,2\},\{1,1,3\},\{1,1,4\},\{1,2,2\},\{1,3,3\},\{1,4,4\},\\&lt;br /&gt;
&amp;amp;\{2,2,2\},\{2,2,3\},\{2,2,4\},\{2,3,3\},\{2,4,4\},\\&lt;br /&gt;
&amp;amp;\{3,3,3\},\{3,3,4\},\{3,4,4\}\\&lt;br /&gt;
&amp;amp;\{4,4,4\}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Combinations with repetitions can be formally defined as &#039;&#039;&#039;multisets&#039;&#039;&#039;. A multiset is a set with repeated elements. Formally, a multiset &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; on a set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is a function &amp;lt;math&amp;gt;m:S\rightarrow \mathbb{N}&amp;lt;/math&amp;gt;. For any element &amp;lt;math&amp;gt;x\in S&amp;lt;/math&amp;gt;, the integer &amp;lt;math&amp;gt;m(x)\ge 0&amp;lt;/math&amp;gt; is the number of repetitions of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt;, called the &#039;&#039;&#039;multiplicity&#039;&#039;&#039; of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;. The sum of multiplicities &amp;lt;math&amp;gt;\sum_{x\in S}m(x)&amp;lt;/math&amp;gt; is called the &#039;&#039;&#039;cardinality&#039;&#039;&#039; of &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; and is denoted as &amp;lt;math&amp;gt;|M|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multiset on a set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is a multiset &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|M|=k&amp;lt;/math&amp;gt;. It is obvious that a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-combination of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; with repetition is simply a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multiset on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The set of all &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multisets on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is denoted &amp;lt;math&amp;gt;\left({S\choose k}\right)&amp;lt;/math&amp;gt;. Assuming that &amp;lt;math&amp;gt;n=|S|&amp;lt;/math&amp;gt;, denote &amp;lt;math&amp;gt;\left({n\choose k}\right)=\left|\left({S\choose k}\right)\right|&amp;lt;/math&amp;gt;, which is the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-combinations of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set with repetitions.&lt;br /&gt;
&lt;br /&gt;
Believe it or not: we have already evaluated the number  &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;z_i=m(x_i)&amp;lt;/math&amp;gt;, then &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt; is the number of nonnegative integer solutions to &amp;lt;math&amp;gt;z_1+z_2+\cdots+z_n=k&amp;lt;/math&amp;gt;, which is the number of weak &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, which we have seen is &amp;lt;math&amp;gt;{n+k-1\choose n-1}={n+k-1\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
There is a direct combinatorial proof that &amp;lt;math&amp;gt;\left({n\choose k}\right)={n+k-1\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Given a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multiset &amp;lt;math&amp;gt;0\le a_0\le a_1\le\cdots\le a_{k-1}\le n-1&amp;lt;/math&amp;gt; on &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt;, then defining &amp;lt;math&amp;gt;b_i=a_i+i&amp;lt;/math&amp;gt;, we see that &amp;lt;math&amp;gt;\{b_0,b_1,\ldots,b_{k-1}\}&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset of &amp;lt;math&amp;gt;[n+k-1]&amp;lt;/math&amp;gt;. Conversely, given a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset &amp;lt;math&amp;gt;0\le b_0\le b_1\le\cdots\le b_{k-1}\le n+k-2&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;[n+k-1]&amp;lt;/math&amp;gt;, then defining &amp;lt;math&amp;gt;a_i=b_i-i&amp;lt;/math&amp;gt;, we have that &amp;lt;math&amp;gt;\{b_0,b_1,\ldots,b_{k-1}\}&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multiset on &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt;. Therefore, we have a bijection between &amp;lt;math&amp;gt;\left({[n]\choose k}\right)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;{[n+k-1]\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Multinomial coefficients ===&lt;br /&gt;
&lt;br /&gt;
== Permutations and Partitions ==&lt;br /&gt;
&lt;br /&gt;
== The twelvfold way ==&lt;br /&gt;
We consider a very fundamental counting framework: counting functions &amp;lt;math&amp;gt;f:N\rightarrow M&amp;lt;/math&amp;gt;. We can define different counting problems according to the types of mapping (1-1, on-to, arbitrary), and the types of the domain and the range (distinguishable, indistinguishable).&lt;br /&gt;
* Distinguishability of set:&lt;br /&gt;
* Types of mapping:&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot;  cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;10&amp;quot; rules=&amp;quot;all&amp;quot;  style=&amp;quot;margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Elements of &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt;&lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Elements of &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; &lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Any &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; &lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Injective (1-1) &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; &lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Surjective (on-to) &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;distinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;distinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;m^n\,&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\left(m\right)_n&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;m!S(n, m)\,&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;indistinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;distinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\left({m\choose n}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;|&amp;lt;math&amp;gt;{m\choose n}&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;|&amp;lt;math&amp;gt;\left({m\choose n-m}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;distinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;indistinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\sum_{k=1}^m S(n,k)&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\begin{cases}1 &amp;amp; \mbox{if }n\le m\\ 0&amp;amp; \mbox{if }n&amp;gt;m\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;S(n,m)\,&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;indistinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;indistinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\sum_{k=1}^m p_k(n)&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\begin{cases}1 &amp;amp; \mbox{if }n\le m\\ 0&amp;amp; \mbox{if }n&amp;gt;m\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;p_m(n)\,&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot;  cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;10&amp;quot; rules=&amp;quot;all&amp;quot;  style=&amp;quot;margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | balls per bin&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | unrestricted &lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | ≤ 1&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | ≥ 1&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; labeled balls, &amp;lt;br&amp;gt;&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; labeled bins&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-tuples &amp;lt;br&amp;gt;of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; things&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-permutations &amp;lt;br&amp;gt;of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; things&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partition of &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt; into &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; ordered parts&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; unlabeled balls, &amp;lt;br&amp;gt;&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; labeled bins&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-combinations of &amp;lt;math&amp;gt;[m]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;with repetitions&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-combinations of &amp;lt;math&amp;gt;[m]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt; without repetitions&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; labeled balls, &amp;lt;br&amp;gt;&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; unlabeled bins&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partitions of &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;\le m&amp;lt;/math&amp;gt; parts&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; pigeons &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; holes&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partitions of &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;\le m&amp;lt;/math&amp;gt; parts&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; unlabeled balls, &amp;lt;br&amp;gt;&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; unlabeled bins&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partitions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;\le m&amp;lt;/math&amp;gt; parts&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; pigeons &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; holes&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partitions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; parts&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
* &#039;&#039;Stanley,&#039;&#039; Enumerative Combinatorics, Volume 1, Chapter 1.&lt;/div&gt;</summary>
		<author><name>0:0:0:0:0:0:0:1</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)&amp;diff=253</id>
		<title>Randomized Algorithms (Spring 2010)</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)&amp;diff=253"/>
		<updated>2009-12-26T15:15:53Z</updated>

		<summary type="html">&lt;p&gt;0:0:0:0:0:0:0:1: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Infobox&lt;br /&gt;
|name         = Infobox&lt;br /&gt;
|bodystyle    = &lt;br /&gt;
|title        = 随机算法 &lt;br /&gt;
Randomized Algorithms&lt;br /&gt;
|titlestyle   = &lt;br /&gt;
&lt;br /&gt;
|image        = [[File:MR-randomized-algorithms.png|100px]]&lt;br /&gt;
|imagestyle   = &lt;br /&gt;
|caption      = &#039;&#039;Randomized Algorithms&#039;&#039; by Motwani and Raghavan&lt;br /&gt;
|captionstyle = &lt;br /&gt;
|headerstyle  = background:#ccf;&lt;br /&gt;
|labelstyle   = background:#ddf;&lt;br /&gt;
|datastyle    = &lt;br /&gt;
&lt;br /&gt;
|header1 =Instructor&lt;br /&gt;
|label1  = &lt;br /&gt;
|data1   = &lt;br /&gt;
|header2 = &lt;br /&gt;
|label2  = &lt;br /&gt;
|data2   = 尹一通&lt;br /&gt;
|header3 = &lt;br /&gt;
|label3  = Email&lt;br /&gt;
|data3   = yitong.yin@gmail.com  yinyt@nju.edu.cn  yinyt@lamda.nju.edu.cn&lt;br /&gt;
|header4 =&lt;br /&gt;
|label4= office&lt;br /&gt;
|data4= 蒙民伟楼 406&lt;br /&gt;
|header5 = Class&lt;br /&gt;
|label5  = &lt;br /&gt;
|data5   = &lt;br /&gt;
|header6 =&lt;br /&gt;
|label6  = Class meetings&lt;br /&gt;
|data6   = 8 am-10 am, Wednesday&lt;br /&gt;
|header7 =&lt;br /&gt;
|label7  = Place&lt;br /&gt;
|data7   = &lt;br /&gt;
|header8 =&lt;br /&gt;
|label8  = Office hours&lt;br /&gt;
|data8   = 2pm-5pm, Saturday, MMW 406 &lt;br /&gt;
|header9 = Textbook&lt;br /&gt;
|label9  = &lt;br /&gt;
|data9   = &lt;br /&gt;
|header10 =&lt;br /&gt;
|label10  = &lt;br /&gt;
|data10   = Motwani and Raghavan, &#039;&#039;Randomized Algorithms&#039;&#039;. Cambridge Univ Press, 1995.&lt;br /&gt;
&lt;br /&gt;
|belowstyle = background:#ddf;&lt;br /&gt;
|below = &lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
This is the homepage for &#039;&#039;Randomized Algorithms&#039;&#039; class for the Spring 2010 semester. Students who take this class should check this page periodically for content updates and new announcements. &lt;br /&gt;
&lt;br /&gt;
= Announcement =&lt;br /&gt;
There is no announcement yet.&lt;br /&gt;
&lt;br /&gt;
= Syllabus =&lt;br /&gt;
随机化（randomization）是现代计算机科学最重要的方法之一，近二十年来被广泛的应用于计算机科学的各个领域。在这些重要应用的背后，有着彼此相通的随机化的原理。在随机算法这门课程中，我们将用数学的语言描述这些原理，将会讲授以下内容：&lt;br /&gt;
* 一些重要的随机算法的设计与分析；&lt;br /&gt;
* 算法的概率论工具，其中包括概率分析的工具，也包括数学证明的概率方法 (the probabilistic method);&lt;br /&gt;
* 随机算法的概率模型，既包括一些算法模型，例如随机漫游 (random walks)，也包括复杂度模型——概率图灵机。&lt;br /&gt;
最为一门理论课，这门课程的内容将侧重数学上的分析和证明，这么做的目的不仅仅是为了结果的严格性，而是因为设计聪明的算法通常都需要人们对问题本身的数学结构有深刻的认识。&lt;br /&gt;
&lt;br /&gt;
=== 先修课程 Prerequisites ===&lt;br /&gt;
必须：离散数学，概率论。&lt;br /&gt;
推荐：算法设计与分析。&lt;br /&gt;
&lt;br /&gt;
=== [[Randomized Algorithms (Spring 2010)/Course materials|教材和参考书 Course materials]] ===&lt;br /&gt;
&lt;br /&gt;
=== [[Randomized Algorithms (Spring 2010)/policies|规则 Policies]] ===&lt;br /&gt;
&lt;br /&gt;
= Assignments =&lt;br /&gt;
&lt;br /&gt;
= Lecture Notes =&lt;/div&gt;</summary>
		<author><name>0:0:0:0:0:0:0:1</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)&amp;diff=252</id>
		<title>Randomized Algorithms (Spring 2010)</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)&amp;diff=252"/>
		<updated>2009-12-26T15:15:32Z</updated>

		<summary type="html">&lt;p&gt;0:0:0:0:0:0:0:1: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Infobox&lt;br /&gt;
|name         = Infobox&lt;br /&gt;
|bodystyle    = &lt;br /&gt;
|title        = 随机算法 &lt;br /&gt;
Randomized Algorithms&lt;br /&gt;
|titlestyle   = &lt;br /&gt;
&lt;br /&gt;
|image        = [[File:MR-randomized-algorithms.png|100px]]&lt;br /&gt;
|imagestyle   = &lt;br /&gt;
|caption      = &#039;&#039;Randomized Algorithms&#039;&#039; by Motwani and Raghavan&lt;br /&gt;
|captionstyle = &lt;br /&gt;
|headerstyle  = background:#ccf;&lt;br /&gt;
|labelstyle   = background:#ddf;&lt;br /&gt;
|datastyle    = &lt;br /&gt;
&lt;br /&gt;
|header1 =Instructor&lt;br /&gt;
|label1  = &lt;br /&gt;
|data1   = &lt;br /&gt;
|header2 = &lt;br /&gt;
|label2  = &lt;br /&gt;
|data2   = 尹一通&lt;br /&gt;
|header3 = &lt;br /&gt;
|label3  = Email&lt;br /&gt;
|data3   = yitong.yin@gmail.com  yinyt@nju.edu.cn  yinyt@lamda.nju.edu.cn&lt;br /&gt;
|header4 =&lt;br /&gt;
|label4= office&lt;br /&gt;
|data4= 蒙民伟楼 406&lt;br /&gt;
|header5 = Class&lt;br /&gt;
|label5  = &lt;br /&gt;
|data5   = &lt;br /&gt;
|header6 =&lt;br /&gt;
|label6  = Class meetings&lt;br /&gt;
|data6   = 8 am-10 am, Wednesday&lt;br /&gt;
|header7 =&lt;br /&gt;
|label7  = Place&lt;br /&gt;
|data7   = &lt;br /&gt;
|header8 =&lt;br /&gt;
|label8  = Office hours&lt;br /&gt;
|data8   = 2pm-5pm, Saturday, MMW 406 &lt;br /&gt;
|header9 = Textbook&lt;br /&gt;
|label9  = &lt;br /&gt;
|data9   = &lt;br /&gt;
|header10 =&lt;br /&gt;
|label10  = &lt;br /&gt;
|data10   = Motwani and Raghavan, &#039;&#039;Randomized Algorithms&#039;&#039;. Cambridge Univ Press, 1995.&lt;br /&gt;
&lt;br /&gt;
|belowstyle = background:#ddf;&lt;br /&gt;
|below = &lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
This is the homepage for &#039;&#039;Randomized Algorithms&#039;&#039; class for the Spring 2010 semester. Students who take this class should check this page periodically for content updates and new announcements. &lt;br /&gt;
&lt;br /&gt;
= Announcement =&lt;br /&gt;
There is no announcement yet.&lt;br /&gt;
&lt;br /&gt;
= Syllabus =&lt;br /&gt;
随机化（randomization）是现代计算机科学最重要的方法之一，近二十年来被广泛的应用于计算机科学的各个领域。在这些重要应用的背后，有着彼此相通的随机化的原理。在随机算法这门课程中，我们将用数学的语言描述这些原理，将会讲授以下内容：&lt;br /&gt;
* 一些重要的随机算法的设计与分析；&lt;br /&gt;
* 算法的概率论工具，其中包括概率分析的工具，也包括数学证明的概率方法 (the probabilistic method);&lt;br /&gt;
* 随机算法的概率模型，既包括一些算法模型，例如随机漫游 (random walks)，也包括复杂度模型——概率图灵机。&lt;br /&gt;
最为一门理论课，这门课程的内容将侧重数学上的分析和证明，这么做的目的不仅仅是为了结果的严格性，而是因为设计聪明的算法通常都需要人们对问题本身的数学结构有深刻的认识。&lt;br /&gt;
&lt;br /&gt;
=== 先修课程 Prerequisites ===&lt;br /&gt;
必须：离散数学，概率论；&lt;br /&gt;
推荐：算法设计与分析&lt;br /&gt;
&lt;br /&gt;
=== [[Randomized Algorithms (Spring 2010)/Course materials|教材和参考书 Course materials]] ===&lt;br /&gt;
&lt;br /&gt;
=== [[Randomized Algorithms (Spring 2010)/policies|规则 Policies]] ===&lt;br /&gt;
&lt;br /&gt;
= Assignments =&lt;br /&gt;
&lt;br /&gt;
= Lecture Notes =&lt;/div&gt;</summary>
		<author><name>0:0:0:0:0:0:0:1</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)&amp;diff=251</id>
		<title>Randomized Algorithms (Spring 2010)</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)&amp;diff=251"/>
		<updated>2009-12-26T15:14:28Z</updated>

		<summary type="html">&lt;p&gt;0:0:0:0:0:0:0:1: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Infobox&lt;br /&gt;
|name         = Infobox&lt;br /&gt;
|bodystyle    = &lt;br /&gt;
|title        = 随机算法 &lt;br /&gt;
Randomized Algorithms&lt;br /&gt;
|titlestyle   = &lt;br /&gt;
&lt;br /&gt;
|image        = [[File:MR-randomized-algorithms.png|100px]]&lt;br /&gt;
|imagestyle   = &lt;br /&gt;
|caption      = &#039;&#039;Randomized Algorithms&#039;&#039; by Motwani and Raghavan&lt;br /&gt;
|captionstyle = &lt;br /&gt;
|headerstyle  = background:#ccf;&lt;br /&gt;
|labelstyle   = background:#ddf;&lt;br /&gt;
|datastyle    = &lt;br /&gt;
&lt;br /&gt;
|header1 =Instructor&lt;br /&gt;
|label1  = &lt;br /&gt;
|data1   = &lt;br /&gt;
|header2 = &lt;br /&gt;
|label2  = &lt;br /&gt;
|data2   = 尹一通&lt;br /&gt;
|header3 = &lt;br /&gt;
|label3  = Email&lt;br /&gt;
|data3   = yitong.yin@gmail.com  yinyt@nju.edu.cn  yinyt@lamda.nju.edu.cn&lt;br /&gt;
|header4 =&lt;br /&gt;
|label4= office&lt;br /&gt;
|data4= 蒙民伟楼 406&lt;br /&gt;
|header5 = Class&lt;br /&gt;
|label5  = &lt;br /&gt;
|data5   = &lt;br /&gt;
|header6 =&lt;br /&gt;
|label6  = Class meetings&lt;br /&gt;
|data6   = 8 am-10 am, Wednesday&lt;br /&gt;
|header7 =&lt;br /&gt;
|label7  = Place&lt;br /&gt;
|data7   = &lt;br /&gt;
|header8 =&lt;br /&gt;
|label8  = Office hours&lt;br /&gt;
|data8   = 2pm-5pm, Saturday, MMW 406 &lt;br /&gt;
|header9 = Textbook&lt;br /&gt;
|label9  = &lt;br /&gt;
|data9   = &lt;br /&gt;
|header10 =&lt;br /&gt;
|label10  = &lt;br /&gt;
|data10   = Motwani and Raghavan, &#039;&#039;Randomized Algorithms&#039;&#039;. Cambridge Univ Press, 1995.&lt;br /&gt;
&lt;br /&gt;
|belowstyle = background:#ddf;&lt;br /&gt;
|below = &lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
This is the homepage for &#039;&#039;Randomized Algorithms&#039;&#039; class for the Spring 2010 semester. Students who take this class should check this page periodically for content updates and new announcements. &lt;br /&gt;
&lt;br /&gt;
= Announcement =&lt;br /&gt;
There is no announcement yet.&lt;br /&gt;
&lt;br /&gt;
= Syllabus =&lt;br /&gt;
随机化（randomization）是现代计算机科学最重要的方法之一，近二十年来被广泛的应用于计算机科学的各个领域。在这些重要应用的背后，有着彼此相通的随机化的原理。在随机算法这门课程中，我们将用数学的语言描述这些原理，将会讲授以下内容：&lt;br /&gt;
* 一些重要的随机算法的设计与分析；&lt;br /&gt;
* 算法的概率论工具，其中包括概率分析的工具，也包括数学证明的概率方法 (the probabilistic method);&lt;br /&gt;
* 随机算法的概率模型，既包括一些算法模型，例如随机漫游 (random walks)，也包括复杂度模型——概率图灵机。&lt;br /&gt;
最为一门理论课，这门课程的内容将侧重数学上的分析和证明，这么做的目的不仅仅是为了结果的严格性，而是因为设计聪明的算法通常都需要人们对问题本身的数学结构有深刻的认识。&lt;br /&gt;
&lt;br /&gt;
=== 先修课程 ===&lt;br /&gt;
必须：离散数学，概率论；&lt;br /&gt;
推荐：算法设计与分析&lt;br /&gt;
&lt;br /&gt;
=== [[Randomized Algorithms (Spring 2010)/Course materials|教材和参考书 Course materials]] ===&lt;br /&gt;
&lt;br /&gt;
=== [[Randomized Algorithms (Spring 2010)/policies|规则 Policies]] ===&lt;br /&gt;
&lt;br /&gt;
= Assignments =&lt;br /&gt;
&lt;br /&gt;
= Lecture Notes =&lt;/div&gt;</summary>
		<author><name>0:0:0:0:0:0:0:1</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)&amp;diff=250</id>
		<title>Randomized Algorithms (Spring 2010)</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)&amp;diff=250"/>
		<updated>2009-12-26T13:03:52Z</updated>

		<summary type="html">&lt;p&gt;0:0:0:0:0:0:0:1: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Infobox&lt;br /&gt;
|name         = Infobox&lt;br /&gt;
|bodystyle    = &lt;br /&gt;
|title        = 随机算法 &lt;br /&gt;
Randomized Algorithms&lt;br /&gt;
|titlestyle   = &lt;br /&gt;
&lt;br /&gt;
|image        = [[File:MR-randomized-algorithms.png|100px]]&lt;br /&gt;
|imagestyle   = &lt;br /&gt;
|caption      = &#039;&#039;Randomized Algorithms&#039;&#039; by Motwani and Raghavan&lt;br /&gt;
|captionstyle = &lt;br /&gt;
|headerstyle  = background:#ccf;&lt;br /&gt;
|labelstyle   = background:#ddf;&lt;br /&gt;
|datastyle    = &lt;br /&gt;
&lt;br /&gt;
|header1 =Instructor&lt;br /&gt;
|label1  = &lt;br /&gt;
|data1   = &lt;br /&gt;
|header2 = &lt;br /&gt;
|label2  = &lt;br /&gt;
|data2   = 尹一通&lt;br /&gt;
|header3 = &lt;br /&gt;
|label3  = Email&lt;br /&gt;
|data3   = yitong.yin@gmail.com  yinyt@nju.edu.cn  yinyt@lamda.nju.edu.cn&lt;br /&gt;
|header4 =&lt;br /&gt;
|label4= office&lt;br /&gt;
|data4= 蒙民伟楼 406&lt;br /&gt;
|header5 = Class&lt;br /&gt;
|label5  = &lt;br /&gt;
|data5   = &lt;br /&gt;
|header6 =&lt;br /&gt;
|label6  = Class meetings&lt;br /&gt;
|data6   = 8 am-10 am, Wednesday&lt;br /&gt;
|header7 =&lt;br /&gt;
|label7  = Place&lt;br /&gt;
|data7   = &lt;br /&gt;
|header8 =&lt;br /&gt;
|label8  = Office hours&lt;br /&gt;
|data8   = 2pm-5pm, Saturday, MMW 406 &lt;br /&gt;
|header9 = Textbook&lt;br /&gt;
|label9  = &lt;br /&gt;
|data9   = &lt;br /&gt;
|header10 =&lt;br /&gt;
|label10  = &lt;br /&gt;
|data10   = Motwani and Raghavan, &#039;&#039;Randomized Algorithms&#039;&#039;. Cambridge Univ Press, 1995.&lt;br /&gt;
&lt;br /&gt;
|belowstyle = background:#ddf;&lt;br /&gt;
|below = &lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
This is the homepage for &#039;&#039;Randomized Algorithms&#039;&#039; class for the Spring 2010 semester. Students who take this class should check this page periodically for content updates and new announcements. &lt;br /&gt;
&lt;br /&gt;
= Announcement =&lt;br /&gt;
There is no announcement yet.&lt;br /&gt;
&lt;br /&gt;
= Syllabus =&lt;br /&gt;
随机化（randomization）是现代计算机科学最重要的方法之一。&lt;br /&gt;
&lt;br /&gt;
* [[Randomized Algorithms (Spring 2010)/Course materials|教材和参考书 Course materials]]&lt;br /&gt;
&lt;br /&gt;
= Assignments =&lt;br /&gt;
&lt;br /&gt;
= Lecture Notes =&lt;/div&gt;</summary>
		<author><name>0:0:0:0:0:0:0:1</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)&amp;diff=249</id>
		<title>Randomized Algorithms (Spring 2010)</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)&amp;diff=249"/>
		<updated>2009-12-26T12:41:57Z</updated>

		<summary type="html">&lt;p&gt;0:0:0:0:0:0:0:1: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Infobox&lt;br /&gt;
|name         = Infobox&lt;br /&gt;
|bodystyle    = &lt;br /&gt;
|title        = 随机算法 &lt;br /&gt;
Randomized Algorithms&lt;br /&gt;
|titlestyle   = &lt;br /&gt;
&lt;br /&gt;
|image        = [[File:MR-randomized-algorithms.png|100px]]&lt;br /&gt;
|imagestyle   = &lt;br /&gt;
|caption      = &#039;&#039;Randomized Algorithms&#039;&#039; by Motwani and Raghavan&lt;br /&gt;
|captionstyle = &lt;br /&gt;
|headerstyle  = background:#ccf;&lt;br /&gt;
|labelstyle   = background:#ddf;&lt;br /&gt;
|datastyle    = &lt;br /&gt;
&lt;br /&gt;
|header1 =Instructor&lt;br /&gt;
|label1  = &lt;br /&gt;
|data1   = &lt;br /&gt;
|header2 = &lt;br /&gt;
|label2  = &lt;br /&gt;
|data2   = 尹一通&lt;br /&gt;
|header3 = &lt;br /&gt;
|label3  = Email&lt;br /&gt;
|data3   = yitong.yin@gmail.com  yinyt@nju.edu.cn  yinyt@lamda.nju.edu.cn&lt;br /&gt;
|header4 =&lt;br /&gt;
|label4= office&lt;br /&gt;
|data4= 蒙民伟楼 406&lt;br /&gt;
|header5 = Class&lt;br /&gt;
|label5  = &lt;br /&gt;
|data5   = &lt;br /&gt;
|header6 =&lt;br /&gt;
|label6  = Class meetings&lt;br /&gt;
|data6   = 8 am-10 am, Wednesday&lt;br /&gt;
|header7 =&lt;br /&gt;
|label7  = Place&lt;br /&gt;
|data7   = &lt;br /&gt;
|header8 =&lt;br /&gt;
|label8  = Office hours&lt;br /&gt;
|data8   = 2pm-5pm, Saturday, MMW 406 &lt;br /&gt;
|header9 = Textbook&lt;br /&gt;
|label9  = &lt;br /&gt;
|data9   = &lt;br /&gt;
|header10 =&lt;br /&gt;
|label10  = &lt;br /&gt;
|data10   = Motwani and Raghavan, &#039;&#039;Randomized Algorithms&#039;&#039;. Cambridge Univ Press, 1995.&lt;br /&gt;
&lt;br /&gt;
|belowstyle = background:#ddf;&lt;br /&gt;
|below = &lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
This is the homepage for &#039;&#039;Randomized Algorithms&#039;&#039; class for the Spring 2010 semester. Students who take this class should check this page periodically for content updates and new announcements. &lt;br /&gt;
&lt;br /&gt;
= Announcement =&lt;br /&gt;
There is no announcement yet.&lt;br /&gt;
&lt;br /&gt;
= Syllabus =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [[Randomized Algorithms (Spring 2010)/Course materials|教材和参考书 Course materials]]&lt;br /&gt;
&lt;br /&gt;
= Lecture Notes =&lt;br /&gt;
&lt;br /&gt;
= Assignments =&lt;/div&gt;</summary>
		<author><name>0:0:0:0:0:0:0:1</name></author>
	</entry>
</feed>