|
|
back to board3 algorithms for you ! 1) Slow algorithm O(K*(K+1)/2) : brute force. AC : 0.2 ! -> Find the profit with each number of horn and hoof (horn + hoof <= k). 2) Fast algorithm O(K*2) : caching the optimal number of horns and hoof. AC : 0.031 ! Find : + The optimal number of horns <= k (A) + The optimal number of hoof <= k - num of horns (B) => result = A + B; 2) More Fast algorithm O(K) : caching the optimal number of horn or hoof. AC : 0.031 ! Caching the number of hoof. -> For each number of horn + The optimal number of hoof = 0 ... k - optimal num of horn. Re: 3 algorithms for you ! first algorithm could be optimized to AC in 0.046 :) |
|
|