zoukankan      html  css  js  c++  java
  • 198. House Robber(LeetCode)

    You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night.

    Given a list of non-negative integers representing the amount of money of each house, determine the maximum amount of money you can rob tonightwithout alerting the police.

     1 class Solution {
     2 public:
     3     int rob(vector<int>& nums) {
     4        int len=nums.size();
     5         if (len == 0)
     6             return 0;
     7         if (len == 1)
     8             return nums.front();
     9         vector<int> vet(len, 0);
    10         vet[0] = nums[0];
    11         vet[1] = max(nums[0], nums[1]);
    12         
    13             for (int i = 2; i < len; i++)
    14             {
    15                 vet[i] = max(vet[i - 2]+nums[i],vet[i-1]);
    16             }
    17             
    18         
    19         return vet[len - 1];
    20         
    21     }
    22 };
  • 相关阅读:
    0421 & SX2016
    HDU3948 & 回文树模板
    BZOJ 2152 & 点分治
    HDU5618 & CDQ分治
    CC countari & 分块+FFT
    ECF R9(632E) & FFT
    ECF R9(632E) & DP
    BZOJ的两道osu概率DP easy与osu
    BZOJ3197 & 组合乱搞
    转载 Rational Rose 的配置和破解
  • 原文地址:https://www.cnblogs.com/wujufengyun/p/7015942.html
Copyright © 2011-2022 走看看