Leetcode 面试题 17.16. 按摩师(DAY 26) ---- 动态规划学习期
作者:互联网
原题题目
代码实现(首刷自解)DP 一遍遍历
int massage(int* nums, int numsSize){
if(!numsSize)
return 0;
int dp[1000] = {0},i,maxtime = -1;
for(i=0;i<numsSize;i++)
{
if(i<=1)
dp[i] = nums[i];
else if(i == 2)
dp[i] = dp[i-2] + nums[i];
else
dp[i] = ((dp[i-3] > dp[i-2]) ? dp[i-3] : dp[i-2]) + nums[i];
if(dp[i] > maxtime)
maxtime = dp[i];
}
return maxtime;
}
标签:numsSize,面试题,return,nums,int,26,maxtime,按摩师,dp 来源: https://blog.csdn.net/qq_37500516/article/details/112823638