Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I need code in Python, please. The input has to be from sys.stdin. This is what I do but it doesn't work: Code: import

Hi, I need code in Python, please. The input has to be from sys.stdin. This is what I do but it doesn't work:

Code:

import sys

import math

def max_distance(segments):

n = len(segments)

dp = [0] * (1

for i in range(n):

for j in range(i+1, n):

for k in range(j+1, n):

if segments[i]

for mask in range(1

if mask & (1

dp[mask] = max(dp[mask], dp[mask & ~(1

return max([dp[mask] + segments[0] / 2.0 for mask in range(1

n = map(int,sys.stdin.strip())

segments = sorted(map(int, sys.stdin.strip().split()), reverse=True)

print("{:.4f}".format(max_distance(segments)))

image text in transcribed

Alaa tondly remembers playing with a construction toy when she was a child. It consisted of segments that could be fastened at each end. A game she liked to play was to start with one segment as a base, placed flat against a straight wall. Then she repeatedly added on triangles, with one edge of the next triangle being a single segment already in place on her structure, and the other two sides of the triangle being newly added segments. She only added real triangles: never with the sum of the lengths of two sides equaling the third. Of course no segment could go through the wall, but she did allow newly added segments to cross over already placed ones. Her aim was to see how far out from the wall she could make her structure go. She would experiment, building different ways with different combinations of some or all of her pieces. It was an easy, boring task if all the segments that she used were the same length! It got more interesting if she went to the opposite extreme and started from a group of segments that were all of distinct lengths. For instance, the figures below illustrate some of the structures she could have built with segments of length 42,40,32,30,25,18 and 15 , including one that reaches a maximum distance of 66.9495 from the wall. (1.a) (1.b)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions