C#, dp, beats 100%. With explanation
The basic idea is you want to count the number of trees with a root of each number in arr.  The sum of all that is the answer.\nIf you sort the array and start 
The basic idea is you want to count the number of trees with a root of each number in arr.  The sum of all that is the answer.\nIf you sort the array and start with the smallest number you will know the number of trees for each factor of this number already, which you can use to compute the number of trees for this number.\n\n```\npublic class Solution {\n    public int NumFactoredBinaryTrees(int[] arr) {\n        var dict = new Dictionary<int,double>();\n        Array.Sort(arr);\n        foreach(var num in arr){\n\t\t\tdict[num] = 1;   //Every number is itself a tree so start with 1\n            var sqrt = Math.Sqrt(num);\n            foreach(var left in arr){\n\t\t\t    //No need to consider factors greater than sqrt(num) because the corresponding\n\t\t\t\t//factor will have already been encountered.\n                if(left>sqrt)\n                    break;\n\t\t\t\t\t\n                if(num%left == 0){                     //If this is a valid factor \n                    var right = num/left;\n                    if(dict.ContainsKey(right)){       //and its corresponding factor is also present..\n\t\t\t\t\t\n                        //Consider all the solutions of the left subtree paird with all the solutions of \n                        //the right subtree, *2 for the case of left & right swapped\n                        dict[num]+=left==right\n                            ? dict[left]*dict[right]       \n                            : 2*dict[left]*dict[right];\n                    }\n                }\n            }\n            //Console.WriteLine($"{num} is root of {dict[num]} trees");\n        }\n        return (int)(dict.Values.Sum() % (Math.Pow(10,9)+7));\n    }\n}\n```
[]