Question: You are asked to implement the 0 / 1 Knapsack Problem using the ARM Cortex MO + architecture. In this problem, each item has a

You are asked to implement the 0/1 Knapsack Problem using the ARM Cortex MO+ architecture. In this problem, each item has a weight (W) and a profit (P). Our knapsack has a limited weight capacity (W). The objective is to maximize the profit without exceeding the weight capacity of the knapsack.
a)(50 Points) You are asked to implement the 0/1 knapsack problem recursively as given below.
```
#define W_Capacity 50
#define SIZE 3
int profit[]={60,100,120};
int weight[]={10,20,30};
int max(int a, int b){
return a>b? a : b;
}
int knapSack(int W, int n)
{
if (n ==0|| w ==0)
return 0;
if (weight[n -1]> w)
return knapSack(W, n -1);
else
return max(knapSack(w, n -1),
profit[n -1]+ knapSack(W - weight[n -1], n -1));
}
void main()
{
int value = knapSack(w_Capacity, SIZE));
while(1);
}
``` b)(50 Points) You are asked to implement the 0/1 knapsack problem iteratively as given below.
```
#define w_Capacity 50
#define SIZE 3
int profit[]={60,100,120};
int weight[]={10,20,30};
int dp[w_Capacity]={0};
int max(int a, int b){
return a>b ? a : b;
}
int knapSack(int W, int n)
{
for (int i =1; i n +1; i++){
for (int w = w; w >=0; w--){
if (weight[i -1]= w)
dp[w]= max(dp[w],
dp[w - weight[i -1]]+ profit[i -1]);
}
}
return dp[W];
}
void main()
{
int value = knapSack(w_Capacity, SIZE));
while(1);
}
```
Constraints:
\(\cdot \) Your main function name or label must be "__main".
- Your code should include a comment for each line. Otherwise, points will be deducted.
- The program must be implemented with Arm Cortex M0+ assembly language.
- Your assembly source file is expected to work with Keil \(\mu \) Vision IDE v5.
- Default configuration must be sufficient to run your programs. If your program expects any different configuration parameter, please write this at the top of the code in comment lines.
- If your program does not run with Keil \(\mu \) Vision IDE you will get zero point from this question.
- At the end of the program, ensure that R0 stores the value variable from the main function, R1 stores the starting address of the profit array, R2 stores the starting address of the weight array, and R3 stores the address of the dp array (if available).
You are asked to implement the 0 / 1 Knapsack

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!