Wooden Fence Recently, Vincent has just bought a farm. He plans to enjoy his retirement by raising horses and goats on his new farm. In order to do that, he needs to build a fence to enclose his farm; otherwise, the horses and goats may escape from his farm. Fortunately, he only needs to build a fence on one side of the farm; the remaining sides are naturally fenced.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Write in C Language

Wooden Fence

Note: Input and Output must be the same

Wooden Fence
Recently, Vincent has just bought a farm. He plans to enjoy his retirement by raising horses and goats on
his new farm. In order to do that, he needs to build a fence to enclose his farm; otherwise, the horses and
goats may escape from his farm. Fortunately, he only needs to build a fence on one side of the farm; the
remaining sides are naturally fenced.
The fence must be exactly 2 unit high and form a perfect rectangle. Why a perfect rectangle? If the fence
has a hole on the upper part, then a horse might jump over it. On the other hand, if the fence has a hole on
the lower part, then a goat might crawl out of it.
Vincent has N boards to be used to build the fence. Each board's dimension is 1 x Lị. Each board may be
placed horizontally (1 x L.) or vertically (L; × 1) as long as the resulting fence has a height of 2.
Oh, have we told you that Vincent is infamous for his stinginess? Yes, he's very stingy. He demands to use
ALL the available boards; he doesn't care about the length of the resulting fence as long as all the boards
are used. Additionally, the boards must not be overlapped as he thinks that it is inefficient (remember that
he's stingy).
Vincent doesn't know whether it is possible to build such a fence with the given constraints. He then asks
you, his only friend to help him. He might give you a present if you could help him, but recalling that he's a
stingy fellow, you want to teach him a lesson. Instead of giving the boards arrangement to build the fence,
you'll only give him a YES or NO whether it is possible to build such a fence, and let Vincent figure out the
rest.
Input
Input begins with an integer N (1 < N < 500) representing the number of boards. The next line contains N
integer Li (1 < Li S 500) representing the length of each board (i.e. 1 x Li).
Output
Output a string either "YES" or "NO" (without quotes) whether it is possible to build a fence that satisfies all
the requirements.
Sample Input #1
4
25 14
Sample Output #1
YES
Transcribed Image Text:Wooden Fence Recently, Vincent has just bought a farm. He plans to enjoy his retirement by raising horses and goats on his new farm. In order to do that, he needs to build a fence to enclose his farm; otherwise, the horses and goats may escape from his farm. Fortunately, he only needs to build a fence on one side of the farm; the remaining sides are naturally fenced. The fence must be exactly 2 unit high and form a perfect rectangle. Why a perfect rectangle? If the fence has a hole on the upper part, then a horse might jump over it. On the other hand, if the fence has a hole on the lower part, then a goat might crawl out of it. Vincent has N boards to be used to build the fence. Each board's dimension is 1 x Lị. Each board may be placed horizontally (1 x L.) or vertically (L; × 1) as long as the resulting fence has a height of 2. Oh, have we told you that Vincent is infamous for his stinginess? Yes, he's very stingy. He demands to use ALL the available boards; he doesn't care about the length of the resulting fence as long as all the boards are used. Additionally, the boards must not be overlapped as he thinks that it is inefficient (remember that he's stingy). Vincent doesn't know whether it is possible to build such a fence with the given constraints. He then asks you, his only friend to help him. He might give you a present if you could help him, but recalling that he's a stingy fellow, you want to teach him a lesson. Instead of giving the boards arrangement to build the fence, you'll only give him a YES or NO whether it is possible to build such a fence, and let Vincent figure out the rest. Input Input begins with an integer N (1 < N < 500) representing the number of boards. The next line contains N integer Li (1 < Li S 500) representing the length of each board (i.e. 1 x Li). Output Output a string either "YES" or "NO" (without quotes) whether it is possible to build a fence that satisfies all the requirements. Sample Input #1 4 25 14 Sample Output #1 YES
Explanation for the sample input/output # 1
4
3
2
You can build a fence with a height of 2 and a length of 6 by placing the 1f and 4th board on the upper part
and the remaining boards on the bottom part.
Sample Input #2
2
2 2
Sample Output #2
YES
Explanation for the sample input/output #2
1
1
2
You can place both boards horizontally (1 x 2) or vertically (2 × 1). Both of them satisfy all the requirements.
Sample Input #3
4
1 3 44
Sample Output #3
NO
Explanation for the sample input/output #3
You cannot build a fence of height 2 and has a form of a perfect rectangle by using all these boards.
2.
Transcribed Image Text:Explanation for the sample input/output # 1 4 3 2 You can build a fence with a height of 2 and a length of 6 by placing the 1f and 4th board on the upper part and the remaining boards on the bottom part. Sample Input #2 2 2 2 Sample Output #2 YES Explanation for the sample input/output #2 1 1 2 You can place both boards horizontally (1 x 2) or vertically (2 × 1). Both of them satisfy all the requirements. Sample Input #3 4 1 3 44 Sample Output #3 NO Explanation for the sample input/output #3 You cannot build a fence of height 2 and has a form of a perfect rectangle by using all these boards. 2.
Expert Solution
steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Problems on Dynamic Programming
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education