Python Knapsack: you are carrying a knapsack with capacity to hold a total of weight C. You are selecting among n items with values A={a1, a2, ... , an} and associated weights W={w1, w2, ... , wn}. Here the weights and values are all positive. You wish to maximize the total value of the items you select not exceeding the given weight capacity, example, maximize sum_{a in A} such that sum_{w in W} <= C. Note that you can only select your items once. In Python, create function DP_K (C, A, W) as stated above. Input an array to the function to hold the backtrace. What is the best set of items for C = 30, A = [40, 110, 100] and w = [20, 30, 40]? This can be shown using auxiliary printing function.
Q: Playing cards are again represented as tuples of (rank,suit) as in the cardproblems.py lecture…
A: Code def winning_card(cards, trump=None): shortlist = [] # will keep possible winner suit…
Q: Problem 1. Solve Quadratic Equations (QuadraticRoot.java) The two roots of a quadratic equation ax +…
A: The below given Java program will obey the following rubrics: Including the required data package.…
Q: Language: JAVA Leap-Year Write a program to find if a year is a leap year or not. We generally…
A: import java.io.*;import java.util.*;class LeapYear { public static void main(String args[]) throws…
Q: Description A researcher is analyzing DNA. A DNA can be represented as a string composed of the…
A: Check further steps for the answer :
Q: Multiples(): Takes an int (n) as parameter and prints first 10 multiples n in a single line using…
A: Introduction of Program: The Java program takes a number as input from the user and then the program…
Q: (PYTHON) A nutritionist who works for a fitness club helps members by evaluating their diets. As…
A: - We yave to help the nutritionist with the code.
Q: Lucky Pairs Richie and Raechal are participating in a game called "Lucky pairs" at the Annual Game…
A: Since no programming language is mentioned, I am using python. Algorithm: Start Read A,B,N values…
Q: Root Finding You are to write a program named Lab5a_Act1.py that will find one single root of a…
A: Actually, python is a easiest programming language. It is a dynamically typed programming language.
Q: (Python GUI -Tkinker) You have a group of friends coming to visit for your high school reunion, and…
A: Ggghbb
Q: Cartesian Product Programming challenge description: The Cartesian product of two lists of numbers A…
A: The solution to the given problem is below.
Q: N ingredients in the menu. Every ingredient has its beauty value that does not depend on its taste,…
A: Given: There is only one list of N ingredients in the menu. Every ingredient has its beauty…
Q: Computer Science Question LabThere is only one list of N ingredients in the menu. Every ingredient…
A: In this problem we need to There is only one list of N ingredients in the menu. Every ingredient has…
Q: Enter the number of days: Day Cents $ 0.01 2 $ 0.02 3 $ 0.04 4 $ 0.08 $ 0.16 $ 0.32 $ 0.64 $ 1.28 $…
A: Find Your Code Below
Q: write a program which will accept one integer argument and returns count of digits of that argument…
A: First, we pass the argument to function Digitcounter using the main function. Using while loop l…
Q: Bad News Bearers Introduction There is some bad news to be delivered, and X has taken on the…
A: Answer: Step 1(INTRODUCTION) This is a basic programming problem named "Jospehus Circle" Since…
Q: Problem Statement An intelligence agency has received reports about some threats. The reports…
A: Given question is asking for a program in c++ language for finding the possible ways to fill the…
Q: 2. Divisibility Of Strings As part of an assignment, a student is required to find whether a given…
A: GIVEN:
Q: Bonus assignment: How to test/find out if two regular expressions are equal with the help of the…
A: A regular expression is a succession of characters that determines a hunt design in text. Normally…
Q: Bulgarian solitaire def bulgarian_solitaire(piles, k): You are given a row of piles of pebbles,…
A:
Q: Java Programming One day, Fred and his N friends were playing a card game in which each player…
A: Java Program for above : import java.util.Scanner; class Prog{ public static void main…
Q: (Population projection) The U.S. Census Bureau projects population based on thefollowing…
A: Program: //declaring the class public class Population { //defining the main method public…
Q: Transcribed Image Text JAVA Programming Problem: In the game of "Assassin's Creed", you control a…
A: As per the given problem statement we are required to develop a JAVA program to output the number of…
Q: Language - Java Script A word is on the loose and now has tried to hide amongst a crowd of tall…
A: Introduction: A word is on the loose and now has tried to hide amongst a crowd of tall letters! Help…
Q: Problem D: Different Dice Game Consider the following game for two players: The first player rolls a…
A: solution: Given, Different Dice Game Consider the following game for two players: The first…
Q: Python Lab: While still in school, Sam had the ability to solve problems. Now one of his friends'…
A: According to the given question we have to create a Python code to solve the given number problem.…
Q: Python Programming The Card Game One day, Fred and his N friends were playing a card game in which…
A: Required: We have to write a code to maximize the sum which we get on the front cards, keeping in…
Q: Homework - identical arrays for one-dimensional: Write a test program which prompts a user to enter…
A: - The question is to check if the two arrays are identical or not. - We are using c++ here.
Q: c. Engineering Application: Electric Field for an Insulating Sphere of Charge Use filename:…
A: #include <iostream> #include <cmath> using namespace std; const double Q = pow(10,-9);…
Q: Write a program that works out the amount a person has to pay for parking in a car park in a tourist…
A: The program is to calculate parking charges. If they say they are disabled, they are told it is…
Q: Use C++. This lab will help you practice with dynamic memory (NOT mixed with classes). Program…
A: The median is the middle number in a sorted, ascending or descending, list of numbers. Algorithm:-…
Q: Geometric Progression Printer As you might recall, a Geometric Progression (or GP) is a sequence of…
A: ALGORITHM:- 1. Take input for the a1, r and the number of terms to generate in the gp. 2. Print the…
Q: Congrats! You work for Zillow now. Your first task is to write an algorithm that recommends…
A: Algorithm: 1. Input Apartment size 2. Input number of pets 3. Input rent 4. Display output
Q: Geometric Progression Printer As you might recall, a Geometric Progression (or GP) is a sequence of…
A: Step-1: Start Step-2: Declare variable a1 and take input from user Step-3: Declare variable r and…
Q: The field of astronomy has been significantly advanced through the use of computer technology.…
A: OUTPUT::
Q: Java Programming One day, Fred and his N friends were playing a card game in which each player…
A: Required: We have to write a code to maximize the sum which we get on the front cards, keeping in…
Q: Java Class: Fundraiser You are a fundraising distributor who needs to to pre-sell a limited number…
A: A java program is defined as a class with a main function defined inside the class. The main program…
Q: Computer Science Question LabThere is only one list of N ingredients in the menu. Every ingredient…
A: Below is the detailed python code for the given problem statement:
Q: Python Assignment: In India McDonald's has the n number of customers and they are famous for their…
A: Coded in Python 3.
Q: Java Programming One day, Fred and his N friends were playing a card game in which each player…
A: Java program to solve the given problem and printing the required output
Q: C++ code Assignment: While still in school, Sam had the ability to solve problems. Now one of his…
A: As per the given problem we are required to develop a C++ to solve the given number problem. For…
Q: rint a ticket indicating the person's seat number and whether it’s in the first class or economy…
A: The below program is a code for railway reservation(seat selection) for users. It has features of…
Q: JAVA CODE PLS Rectangle by CodeChum Admin A rectangle can be formed given two points, the top left…
A: Answer :
Q: The Card Game One day, Fred and his N friends were playing a card game in which each player throws a…
A: As per question, we required an algorithm Algorithm: 1. First calculate the total sum of the input…
Q: https://www.codingame.com/ide/puzzle/horse-racing-hyperduals Casablanca’s hippodrome has grown…
A: Here we have to write a program for given requirements. Here Python programming is used
Q: Trivia Game In this programming exercise, you will create a simple trivia game for two players. The…
A: Question.py • Define the class named “Question”. ○ Define “__init__()” method for “Question”…
Q: The game of "23" is a two-player game that begins with a pile of 23 toothpicks. Players take turns,…
A: Since no programming language is mentioned, I am using python. Algorithm: Start import random…
Q: by CodeChum Admin (JAVA CODE) Construct a class called Term. It is going to represent a term in…
A: According to the Question below the Solution: Output:
Q: Python Development Lab In Merworld there exists 2 coins of different denominations types 5-peso…
A: Python code to perform the given conditions is as given below.
Q: Python Lab: While still in school, Sam had the ability to solve problems. Now one of his friends'…
A: Algorithm: 1. take the input 2. apply the condition 3. return output
Q: Treasure Hunter description You are in front of a cave that has treasures. The cave can…
A: Given The answer is given below
Python Knapsack: you are carrying a knapsack with capacity to hold a total of weight C. You are selecting among n items with values A={a1, a2, ... , an} and associated weights W={w1, w2, ... , wn}. Here the weights and values are all positive. You wish to maximize the total value of the items you select not exceeding the given weight capacity, example, maximize sum_{a in A} such that sum_{w in W} <= C. Note that you can only select your items once.
- In Python, create function DP_K (C, A, W) as stated above. Input an array to the function to hold the backtrace. What is the best set of items for C = 30, A = [40, 110, 100] and w = [20, 30, 40]? This can be shown using auxiliary printing function.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images
- JAVA CODE PLEASE THANK YOU Rectangle by CodeChum Admin A rectangle can be formed given two points, the top left point and the bottom right point. Assuming that the top left corner of the console is point (0,0), the bottom right corner of the console is point (MAX, MAX) and given two points (all "x" and "y" coordinates are positive), you should be able to draw the rectangle in the correct location, determine if it is a square or a rectangle, and compute for its area, perimeter and center point. To be able to do this, you should create a class for a point (that has an x-coordinate and a y-coordinate). Also, create another class called Rectangle. The Rectangle should have 2 points, the top left and the bottom right. You should also implement the following methods for the Rectangle: display() - draws the rectangle on the console based on the sample area() - computes and returns the area of a given rectangle perimeter() - computes and returns the perimeter of a given rectangle…C++ programming It has been observed by management that some faculty member at the university demonstrates a lackadaisical attitude toward work. They seldom go to class yet at the end of each month they receive full salary. Management has decided that GHs 200, 300, 400, and 500 will be deducted from a faculty’s salary if he/she offends once, twice, third time and forth time respectively in a month. This means that if a faculty member offends once in a month GHs 200 will be deducted, if a faculty member offends twice in a month, GHs 500 (i.e. 200+300) will be deducted, if a faculty member offends three times in a month GHs 900 (i.e.200+300+400), will be deducted and if a faculty member offends four times in a month GHs 1,400 (i.e. 200+300+400+500). Assuming all faculty members are on a flat salary rate of GHs 2500. a. Write a program to request for the names of four faculty members and number times he/she has absented him/herself from class. One of them should have absented him/herself…Lucky Pairs Richie and Raechal are participating in a game called "Lucky pairs" at the Annual Game Fair in their Company. As per the rules of the contest, two members form a team and Richie initially has the number A and Raechal has the number B.There are a total of N turns in the game, and Richie and Raechal alternatively take turns. In each turn, the player's number is multiplied by 2. Richie has the first turn. Suppose after the entire N turns, Richie’s number has become C, and Raechal’s number has become D, the final score of the team will be the sum of the scores (C+D) of both the players after N turns. Write a program to facilitate the quiz organizers to find the final scores of the team. Input and Output Format:The only line of input contains 3 integers A, B, and N.Output a single line that contains the integer that gives the final score of the team which will be the sum of the scores of both the players after N turns.Refer sample input and output for formatting specifications.…
- When you borrow money to buy a house, a car, or for some other purpose, you repay the loan by making periodic payments over a certain period of time. Of course, the lending company will charge interest on the loan. Every periodic payment consists of the interest on the loan and the payment toward the principal amount. To be specific, suppose that you borrow $1,000 at an interest rate of 7.2% per year and the payments are monthly. Suppose that your monthly payment is $25. Now, the interest is 7.2% per year and the payments are monthly, so the interest rate per month is 7.2/12 = 0.6%. The first months interest on $1,000 is 1000 0.006 = 6. Because the payment is $25 and the interest for the first month is $6, the payment toward the principal amount is 25 6 = 19. This means after making the first payment, the loan amount is 1,000 19 = 981. For the second payment, the interest is calculated on $981. So the interest for the second month is 981 0.006 = 5.886, that is, approximately $5.89. This implies that the payment toward the principal is 25 5.89 = 19.11 and the remaining balance after the second payment is 981 19.11 = 961.89. This process is repeated until the loan is paid. Write a program that accepts as input the loan amount, the interest rate per year, and the monthly payment. (Enter the interest rate as a percentage. For example, if the interest rate is 7.2% per year, then enter 7.2.) The program then outputs the number of months it would take to repay the loan. (Note that if the monthly payment is less than the first months interest, then after each payment, the loan amount will increase. In this case, the program must warn the borrower that the monthly payment is too low, and with this monthly payment, the loan amount could not be repaid.)1. Astronomy Board Game In an astronomy board game, N planets in an imaginary universe do not follow the normal law of gravitation. All the planets are positioned in a row. The planetary system can be in a stable state only if the sum of the mass of all planets at even positions is equal to the sum of the mass of planets at the odd positions. Initially, the system is not stable, but a player can destroy one planet to make it stable. Find the planet that should be destroyed to make the system stable. If no such planet exists, then return -1. If there are multiple such planets, then destroy the planet with the smallest index and return the index of the destroyed planet. Example Let N=5 and planets = [2,4,6,3,4]. Destroying the fourth planet of mass 3 will result in planets= [2,4,6,4], and here, the sum of odd positioned planets is (2+6)=8, and the sum of even positioned planets is (4+4)=8, and both are equal now. Hence, we destroy the fourth planet. Function Description Complete the…Language C++ It has been observed by management that some faculty member at the university demonstrates a lackadaisical attitude toward teaching. They seldom go to class yet at the end of each month they receive full salary. Management has decided that GHs 200, 300, 400, and 500 will be deducted from a faculty’s salary if he/she offends once, twice, third time and forth time respectively in a month. This means that if a faculty member offends once in a month GHs 200 will be deducted, if a faculty member offends twice in a month, GHs 500 (i.e. 200+300) will be deducted, if a faculty member offends three times in a month GHs 900 (i.e. 200+300+400), will be deducted and if a faculty member offends four times in a month GHs 1,400 (i.e. 200+300+400+500). Assuming all faculty members are on a flat salary rate of GHs 2000. a. Write a program to request for the names of four faculty members and number times he/she has absented him/herself from class. One of them should have absented…
- Direction Fields Plotting Direction fields can be done using the function quiver: quiver Quiver plot. quiver (X,Y.U.V) plots velocity vectors as arrows with components (u.v) at the points (x,y). The matrices X,Y,U,V must all be the same size and contain corresponding position and velocity components (X and Y can also be vectors to specify a uniform grid). quiver automatically scales the arrows to fit within the grid. Example: xrange = -5:0.5:5; %the domain of x is from -5 up to 5 with 0.5 interval. yrange= -10:1:10; %the values of y is from -10 up to 10 with 1 interval. [x,y] meshgrid(xrange,yrange); Xplot the DE y = x^2+y^2; S = x.^2+y^2; quiver (x,y,ones (size(s)),s) Exercises: Sketch the direction fields of the following differential equations 1. y = 0.25xy² 2. y = sin(x-y) Notes: For the ranges: For Item No.1 Use xr1 = (-5,5) with 0.5 interval yr1 = (-10,10) with 0.5 interval Use s1 for the f(x,y). x1 and y1 as the points in the rectangular coordinate system, For Item No.2 Use xr2…HASKELL PROGRAMMING LANGUAGE QUESTION PLEASE Rock-paper-scissors is a game for two players. Each player chooses an action without knowledge ofthe other’s choice. If the players choose the same action then there is a draw. Otherwise the winneris determined by the following rules: paper beats rock, rock beats scissors, and scissors beats paper.you are going to make a playable Rock-Paper-Scissors game and consider multiplayer tournaments • Please put comments in your code to show what you are answering with each piece ofcode. • You may create auxiliary functions if you like. You may use library functions from Haskell’sstandard library.• Please limit your line lengths to 100 characters max. Please use the following two data types which you can copy-and-paste into your code.data Action = Rock | Paper | Scissors deriving (Eq, Show)data Outcome = Player1Win | Player2Win | Draw deriving ShowAction represents a player’s chosen action and Outcome represents the outcome of playing a game…Turtle Hare Race Use two Timer objects to write a Java program to simulate the race between turtle and hare. The hare runs faster than the turtle, but it may sleep once or twice during each race. You should take the following requirements into account: The user is allowed to define whether the hare will not sleep, will sleep once, or will sleep twice during the race, by clicking point(s) along the lane. If the user clicks more than twice, only the first two should be considered. The user is allowed to define the speed of the turtle and of the hare. The two numbers input from the user indicate the numbers of milliseconds for each step of the tortoise and for each step of the hare. The user is also allowed to define the sleep time of the hare in milliseconds. If the hare sleeps twice during a race, it sleeps the same amount of time. For each race, the program should provide the result who has won. In Java Please
- Dinah Shore of Shore We Can Building is attempting to determine the cost forbuilding a custom lumber dog house. Each dog house starts at a cost of $1000. Eachhouse has a different possible size in square feet, which the user will enter. The sizein square feet must be in the range of 1200-2000 inclusive. However, since each doghouse is made from found wood, the actual size of the dog house varies depending onthe materials they have on hand. Once the size has been entered, create a randomnumber to determine the actual size the house will be. This size number should be inthe range of 800 to 2200. If the actual size of the dog house is over the squarefootage the user entered, they only get charged $3 per square foot. If the actual sizeis equal to or under the square footage entered they get charged $4 per squarefoot. The program should calculate the total cost for the dog house. The output forthis program must include the customer’s name, entered size, actual size and totalcost, in that…Sum of two squares def sum_of_two_squares(n): Some positive integers can be expressed as a sum of two squares of some positive integers greater than zero. For example, 74 = 49 + 25 = 72 + 52. This function should find and return a tuple of two positive integers whose squares together add up to n, or return None if the parameter n cannot be broken into a sum of two squares. To facilitate the automated testing, the returned tuple must present the larger of its two numbers first. Furthermore, if some integer can be broken down to a sum of squares in several ways, return the breakdown that maximizes the larger number. For example, the number 85 allows two such representations 72 + 62 and 92 + 22 , of which this function must return (9, 2). The technique of two approaching indices that start from the beginning and end of a sequence, respectively, and approach each other until they meet somewhere, used in the function two_summers in one of our class examples, is directly applicable to this…Sum of two squares def sum_of_two_squares(n): Some positive integers can be expressed as a sum of two squares of some positive integers greater than zero. For example, 74 = 49 + 25 = 72 + 52. This function should find and return a tuple of two positive integers whose squares together add up to n, or return None if the parameter n cannot be broken into a sum of two squares.To facilitate the automated testing, the returned tuple must present the larger of its two numbers first. Furthermore, if some integer can be broken down to a sum of squares in several ways, return the breakdown that maximizes the larger number. For example, the number 85 allows two such representations 72 + 62 and 92 + 22 , of which this function must return (9, 2).The technique of two approaching indices that start from the beginning and end of a sequence, respectively, and approach each other until they meet somewhere, used in the function two_summers in one of our class examples, is directly applicable to this…