POJ 1837 Balance (multiple pack count)

Source: Internet
Author: User
Tags integer numbers


Balance
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 11706 Accepted: 7305

Description

gigel have a strange "balance" and he wants to poise it. Actually, the device is different from any and ordinary balance.
It orders arms of negligible weight and each arm's length is 15. Some Hooks is attached to these arms and Gigel wants to hang up Some weights from his collection of G weights (1 <= g <=) Knowing that these weights has distinct values in the range 1..25. Gigel may droop any weight of any hooks but he's forced to use all the weights.
Finally, Gigel managed to balance the device using the experience he gained at the National Olympiad in Informatics. N Ow he would like into know in what many ways the device can be balanced.

Knowing the repartition of the hooks and the set of the weights write a program that calculates the number of poss Ibilities to balance the device.
It is guaranteed, that would exist at least one solution for each test case at the evaluation.

Input

The input has the following structure:
? The first line contains the number C (2 <= C <=) and the number G (2 <= G <= 20);
? The next line contains C integer numbers (these numbers is also distinct and sorted in ascending order) in the range-15. . Representing the repartition of the hooks; Each number represents the position relative to the center of the balance in the X axis (when no weights is attached the Device is balanced and lined up to the X axis; The absolute value of the distances represents the distance between the hook and the balance center and the sign of the Nu Mbers determines the arm of the the balance to which the hook was attached: '-' for the left arm and ' + ' for the right arm);
? On the next line there is G natural, distinct and sorted in ascending order numbers in the range 1..25 representing the W Eights ' values.

Output

The output contains the number M representing the number of possibilities to poise the balance.

Sample Input

2 4-2 3 3 4 5 8

Sample Output

2

Source

Romania OI 2002

Title Link: http://poj.org/problem?id=1837

A balance has a C position has a hook minus sign in the midpoint of the left, there are g weights, each heavy GI, ask the balance plan number

Title Analysis: According to the lever theorem can be obtained arm * length equals torque, balance balance is equal torque on both sides, the largest case is 15*20*25=7500, the right to move, that is, 0-15000, take dp[i][j] to indicate the use of I weights so that the balance of the program number of J, And then use the number of multiple backpacks, obviously dp[g][7500] is the final answer

#include <cstdio> #include <cstring>int cc, Gg;int c[25], g[25];int dp[25][15005];int main () {    scanf ("%d %d ", &CC, &gg);    for (int i = 1; I <= cc; i++)        scanf ("%d", &c[i]);    for (int i = 1; I <= GG; i++)        scanf ("%d", &g[i]);    DP[0][7500] = 1;    for (int i = 1, i <= GG; i++) for        (int j = 1; J <= 15000; j + +)            if (Dp[i-1][j]) for                (int k = 1; k <= cc; k++)                    dp[i][j + g[i] * C[k]] + + dp[i-1][j];     printf ("%d\n", dp[gg][7500]);}   




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ 1837 Balance (multiple pack count)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.