exact algorithm