int buff[20]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
// 计算两个数中的较大值
/* *****************************************************************
- 函数功能: 取2个房子中的最大金额
- 输入参数:
- Aamount: A 房子的金额数
- Bamount: B 房子的金额数
- 输出参数: 无
- 返回:
-
2个 房子中的最大金额数
***************************************************************** */
int max_amount(int Aamount, int Bamount)
{
return Aamount > Bamount? Aamount : Bamount;
}
/* *****************************************************************
- 函数功能:计算不触动警报装置的情况下 ,一夜之内能够偷窃到的最高金额
-
Leetcode.198.打家劫舍
- 输入参数:
-
houseAmounts -- 数组:每个房屋存放的金额
-
houseCount -- 房屋个数
- 输出参数:
- 返回:
-
数据
***************************************************************** */
int highest_stolen_amount( int *houseAmounts, int houseCount )
{
if (houseCount == 0)
{
return 0;
}
if (houseCount == 1)
{
return houseAmounts[0];
}
int Max_amount[houseCount];
Max_amount[0] = houseAmounts[0];
Max_amount[1] = max_amount(houseAmounts[0], houseAmounts[1]);
for (int i = 2; i < houseCount; i++)
{
Max_amount[i] = max_amount(Max_amount[i - 1], Max_amount[i - 2] + houseAmounts[i]);
}
printf("Max_amount[houseCount - 1]:%d \n",Max_amount[houseCount - 1]);
return Max_amount[houseCount - 1];
}
int main(int argc, char *argv[])
{
printf("hello world!\n");
int data_lenth = 0;
data_lenth = sizeof(buff)/4 ;
printf("data_lenth:%d \n",data_lenth);
// thief(buff,data_lenth);
highest_stolen_amount(buff,data_lenth);
return 0;
}