标签:min ble win out 思路 set 包含 com int
我们把只包含质因子2、3和5的数称作丑数(Ugly Number)。
例如6、8都是丑数,但14不是,因为它包含质因子7。
求第n个丑数的值。
class Solution { public: int getUglyNumber(int n) { int dp[n]; memset(dp,0,sizeof(dp)); dp[1] = 1; int t1= 1, t2 = 1, t3 = 1; for(int i = 2; i <= n; i++){ dp[i] = min({2*dp[t1],3*dp[t2],5*dp[t3]}); // cout <<dp[i]; if(dp[i]%2 == 0) t1++; if(dp[i]%3 == 0) t2++; if(dp[i]%5 == 0) t3++; } return dp[n]; } };
标签:min ble win out 思路 set 包含 com int
原文地址:https://www.cnblogs.com/Aliencxl/p/12369335.html