In the Spring and Autumn Period, the State of Wu defeated the State of Yue, and took the king of Yue, Gou Jian, and his wife prisoner. For several years, Gou Jian laboured as a slave in Wu. When he was released and returned to Yue, Gou Jian was determined to take revenge for losing his state. So that he would never forget his humiliation, he slept on a pile of brushwood and tasted gall before every meal. After ten years of careful preparations, he attacked and finally conquered the State of Wu.
This idiom is used to describe inspiring oneself and working hard to accomplish an ambition.