Ruby 100%. Explanation. Image.
Leetcode: 1039. Minimum Score Triangulation of Polygon.\n\nThis is a recursive function. To calculate a minimum split into triangle pices we select one edge bet
#### Leetcode: 1039. Minimum Score Triangulation of Polygon.\n\nThis is a recursive function. To calculate a minimum split into triangle pices we select one **edge** between to vertex (let it be an edge between first and last vertex). And draw all possible triangles with this **edge**. It will be **N-2** triangles, because there are **N-2** vertexes beside first and last one.  In this funcion we split the poigon in three sub poligons: **prev poligon**, triange that used this edge, and **future poligion**. \nFor eaxmple if we have 5 vertexes with indices 0, 1, 2, 3, 4, it\'s could be **prev poligon: [0,1,2]**,  **triange: [0,2,4]**, **future poligion: [2,3,4]**. Each of this poligons could be send in recursive call, or calculated inplace if it has 3 sides.\n\n![Examples of splitting the poligons in 3 pats, for recursive calls](https://assets.leetcode.com/users/user9697n/image_1586455094.png)\n\n\n```Ruby\n# 1039. Minimum Score Triangulation of Polygon\n# https://leetcode.com/problems/minimum-score-triangulation-of-polygon/\n# Runtime: 84 ms, faster than 100.00% of Ruby online submissions for Minimum Score Triangulation of Polygon.\n# Memory Usage: 9.5 MB, less than 100.00% of Ruby online submissions for Minimum Score Triangulation of Polygon.\n# @param {Integer[]} a\n# @return {Integer}\ndef min_score_triangulation(a)\n    @h = Array.new(a.size).map{Array.new(a.size)}\n    @a = a\n    rec(0,a.size-1)\n    \nend\n\ndef rec(first,last)\n    size = last - first + 1\n    return 0 if 3 > size\n    return @a[first+0]*@a[first+1]*@a[first+2] if 3 == size\n    return @h[first][last] if @h[first][last]\n    min = 1_000_000\n    finish = last\n    (first+1...finish).each do |k|\n        prev_val = rec(first,k)\n        cur_val = @a[first] * @a[k] * @a[finish]\n        future_val = rec(k,finish)\n        total = prev_val+cur_val+future_val\n        min = total if total < min\n    end\n    @h[first][last] = min\n    return min\n\nend\n```
['Ruby']