Answers to: How to optimise solution for PRITREE ?https://discuss.codechef.com/questions/140459/how-to-optimise-solution-for-pritree<p>I was wondering how best to optimize the solution for PRITREE. The way I approached was I generated random trees and permuted the values among their nodes and kept saving the best one. I even kept partitioning the primes to the leaves with some probability.
I was wondering how better to solve this (I couldn't find the editorial link for this).</p>
<p>Link to my <a href="https://www.codechef.com/viewsolution/21612900">solution</a></p>
<p>P.S: This is my first attempt at a Challenge problem.</p>enFri, 16 Nov 2018 23:20:22 +0530Answer by gkashishhttps://discuss.codechef.com/questions/140459/how-to-optimise-solution-for-pritree/140496<p>In my solution, I inserted elements into a heap such that if the node is not prime and (totalSum - sumOfNodeSubtree) is not prime it appears at the front of the heap and if node is prime and (totalSum - sumOfNodeSubtree) is prime, it goes at the end. I took the first element of the heap, made it a parent (no point in making it a leaf) and chose its child such that the sum of the two nodes is of latter type (if possible), and child should preferably be at the lower end of the heap. Inserted parent back into the heap with updated sum.<br><br>
It was quite greedy, still got 91 points. Here is my <a href="https://www.codechef.com/viewsolution/21526306">solution</a>.</p>gkashishFri, 16 Nov 2018 23:20:22 +0530https://discuss.codechef.com/questions/140459/how-to-optimise-solution-for-pritree/140496Answer by euler1https://discuss.codechef.com/questions/140459/how-to-optimise-solution-for-pritree/140462<p>I developed a solution, where I was only developing a linear tree ( a three node tree will be like 1-2-3). I found out the next node to join in the current tree by finding if the current tree node sum or the remaining node sum becomes prime after joining the node. I kept doing this through a greedy approach.</p>
<p>The major constraint was that trees could only be linear but I still managed 88.6 points. <a href="https://www.codechef.com/viewsolution/21603755">Link</a> to the solution.</p>euler1Fri, 16 Nov 2018 13:53:59 +0530https://discuss.codechef.com/questions/140459/how-to-optimise-solution-for-pritree/140462