Question
Using R programming: You are a smart thief. You plan to steal money from houses along a street. There are n houses along a street,
Using R programming:
You are a smart thief. You plan to steal money from houses along a street.
There are n houses along a street, each house has certain amount of cash stashed.
You want to steal as much money as possible. However, adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were both broken into.
Given a sequence of non-negative integers representing the amount of money of each house, determine the maximum amount of money you can steal without alerting the police.
Write an R function that takes the amount of money of each house as input, and the following as outputs: (1) the maximum amount you can steal. (2) the strategy (stealing /not stealing each house) to achieve the maximum amount.
Test your function using the input:
set.seed(250) House.money = round(runif(n=100, min=10, max=1000),digits=0)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started