Editing
2015 Open Bronze Problem 2 Bessie Gets Even
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Solution == This problem can be solved using a technique known as dynamic programming. Firstly, for each number between 1 to 10, we count the frequency of its occurrence in the list. Let's denote this frequency as freq[i]. We can then create a 2D dynamic programming table, dp[i][j], where dp[i][j] represents the number of ways to make a sum of j using the first i numbers. We initially set dp[0][0] to 1 since there is only one way to create a sum of 0, that is by taking no numbers at all. Then, for each number i from 1 to 10, we perform the following steps: * We create a temporary copy of the DP table. * We then iterate through all possible sums j from 0 to 20. For each sum, we consider adding k copies of the current number i, where k can range from 0 to freq[i]. For each valid k, we add the number of ways to form the sum j - k * i (from the previous set of numbers) to dp[i][j]. * After we've finished processing the current number i, we copy the temporary DP table back to the original one. Finally, the answer to the problem is dp[10][0], since we want to count the number of ways to form an even sum (which is 0 modulo 2).
Summary:
Please note that all contributions to Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
My wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information