LeetCode "Paint House"
2015-08-22 00:46
309 查看
A typical DP
class Solution { public: int minCost(vector<vector<int>>& costs) { size_t len = costs.size(); if(len == 0) return 0; vector<vector<int>> dp(len, vector<int>(3, 0)); dp[0] = costs[0]; for(int i = 1; i < len; i ++) { for(int c = 0; c < 3; c ++) { unordered_set<int> cand = {0, 1, 2}; cand.erase(c); auto it = cand.begin(); int a = *it ++, b = *it; dp[i][c] = costs[i][c] + std::min(dp[i - 1][a], dp[i - 1][b]); } } return *std::min_element(dp[len - 1].begin(), dp[len - 1].end()); } };
相关文章推荐
- hdu 5316 Magician 2015 Multi-University Training Contest 3
- 关于pkg: /data/local/tmp/com.example.zy.deyijia Failure [INSTALL_FAILED_OLDER_SD问题
- 【LeetCode】(172)Factorial Trailing Zeroes(Easy)
- uva 11168 - Airport(凸包)
- Selenium 高阶应用之WebDriverWait 和 expected_conditions
- Selenium 高阶应用之WebDriverWait 和 expected_conditions
- 2015 Multi-University Training Contest 10 hdu 5411 CRB and Puzzle
- wget+webmin+dns+lamp+openwebmail
- hdu1021Fibonacci Again
- [杂谈]机器学习:数学、概率与人工智能
- Codeforces Gym 100338H High Speed Trains 组合数学+dp+高精度
- ip,email,银行卡号匹配
- 03-树3. Tree Traversals Again (25)将先序遍历和中序遍历转为后序遍历
- main函数的参数(一)
- USACO 2009 Feb Gold 3.Revamping Trails
- editor does not contain a main type 解决方法
- codeforces Gym 100338H High Speed Trains (递推,高精度)
- 具有 Button 风格的 Panel(覆盖TCustomPanel的Paint函数,用到了ThemeServices)
- HDOJ1021题 Fibonacci Again 应用求模公式
- HDOJ1021题 Fibonacci Again 应用求模公式