Example 10 Given a positive integer $n$, it is known that $k$ weights with masses being positive integers and a balance can measure all items with masses of $1,2, \cdots n$ grams. Find the minimum value of $k$, denoted as $f(n)$.
(1999 National High School League Additional Test Question)
Let the masses of $k$ weights be $a_{1}, a_{2}, \cdots, a_{k}$ grams, and $1 \leqslant a_{1} \leqslant a_{2} \leqslant \cdots \leqslant a_{k}\left(a_{i} \in \mathbf{N}_{+}, 1 \leqslant\right.$ $i \leqslant k)$. Since weights can be placed on both sides of the balance, the mass that can be measured is $\sum_{i=1}^{k} x_{i} a_{i}, x_{i} \in\{-1,0,1\}$. If using these $k$ weights can measure the mass of items that are $1,2, \cdots, n$ grams, then the above expression can represent $1,2, \cdots, n$, and by symmetry, it can also represent $0,-1,-2, \cdots,-n$, i.e.,
$$
\left\{\sum_{i=1}^{k} x_{i} a_{i} \mid x_{i} \in\{-1,0,1\}\right\} \supseteq\{0, \pm 1, \pm 2, \cdots, \pm n\} .
$$

Thus, $2 n+1=|\{0, \pm 1, \pm 2, \cdots, \pm n\}|\leqslant|\left\{\sum_{i=1}^{k} x_{i} a_{i} \mid x_{i} \in\{-1,0,1\}\right\} \mid \leqslant 3^{k}$,
i.e., $3^{k}>2 n$, so $k>\log _{3} 2 n \geqslant\left[\log _{3} 2 n\right]$. Therefore, $k \geqslant\left[\log _{3} 2 n\right]+1$.
Thus, the minimum value of $n$ is $f(n) \geqslant\left[\log _{3} 2 n\right]+1$.
On the other hand, for any positive integer $n$, there exists a positive integer $k$ such that $3^{k}>2 n \geqslant 3^{k-1}$, i.e., $\log _{3} 2 n<k<\log _{3} 2 n+1$, so $k=\left[\log _{3} 2 n\right]+1$. Taking $a_{1}=1, a_{2}=3, \cdots, a_{k}=3^{k-1}$, by the ternary representation of numbers, for any $0 \leqslant p \leqslant 3^{k}-1$, there exist $y_{i} \in\{0,1,2\}(i=1,2, \cdots, k)$ such that
$p=\sum_{i=1}^{k} y_{i} a_{i}$.
Thus, $p-\frac{3^{k}-1}{2}=\sum_{i=1}^{k} y_{i} a_{i}-\sum_{i=1}^{k} 3^{i-1}=\sum_{i=1}^{k}\left(y_{i}-1\right) a_{i}$.
Let $x_{i}=y_{i}-1$, then $x_{i} \in\{-1,0,1\},-\frac{3^{k}-1}{2} \leqslant p-\frac{3^{k}-1}{2} \leqslant \frac{3^{k}-1}{2}$, hence for all integers $l$ satisfying $-\frac{3^{k}-1}{2} \leqslant l \leqslant \frac{3^{k}-1}{2}$, there exist $x_{i} \in\{-1,0,1\}(i=1,2, \cdots, k)$ such that $l=\sum_{i=1}^{k} x_{i} a_{i}$.
Since $2 n<3^{k}$, we have $2 n \leqslant 3^{k}-1, n \leqslant \frac{3^{k}-1}{2}$, so for all $l$ satisfying $-n \leqslant l \leqslant n$, the above equation still holds. Therefore, using weights of mass $a_{1}, a_{2}, \cdots, a_{k}$ on the balance can measure any item of mass $1,2, \cdots, n$ grams.
In summary, the minimum value of $k$ is $f(m)=\left[\log _{3} 2 n\right]+1$.