Define as the minimum number of perfect squares that sum to . You want .
For each , try subtracting all perfect squares . Then for all valid . The base case is .
How many perfect squares are there? About . So for each , you do work. Total time: .
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
Building from smaller values
Define as the minimum number of perfect squares that sum to . You want .
For each , try subtracting all perfect squares . Then for all valid . The base case is .
How many perfect squares are there? About . So for each , you do work. Total time: .