Link: poj 1837
Question:There is a balance, there are several hooks on both sides of the balance, a total of C hooks, G hook code,
Evaluate the total number of methods that hook the hook to balance the balance. In this example, we can regard the day sequence as a horizontal axis with the X axis 0 as the equilibrium point.
Analysis:Arm = weight * arm length = G [I] * C [J]
When the degree of balance K is 0, it means that the balance will be reached tomorrow, K is> 0, it means that tomorrow's balance tends to the right side (the right half axis of the X axis), and K is less than 0, it is left
Therefore, you can define a status array DP [I] [K], which indicates the number of hooks with a degree of balance of K when the first I hooks are full.
Since the distance from C [I] is-15 ~ 15. The hook weight ranges from 1 ~ 25. The maximum number of hooks is 20.
Therefore, the most extreme degree of balance is that all objects are mounted at the far end. ThereforeThe maximum degree of balance is J = 15*20*25 = 7500..
In principle, DP [1 ~ 20] [-7500 ~ 7500].
Therefore, in order not to let negative numbers appear in the subscript, make a processing to enable the array to be DP [1 ~ 20] [0 ~ 15000], then when J = 7500, the daily timeout is in the balance status.
The state equation is DP [I] [k] + = DP [I-1] [k-G [I] * C [J];
# Include <stdio. h> # include <string. h> int DP [21] [1, 15010]; int main () {int m, n, I, J, K, C [21], G [21]; scanf ("% d", & M, & N); for (I = 1; I <= m; I ++) scanf ("% d ", & C [I]); for (I = 1; I <= N; I ++) scanf ("% d", & G [I]); memset (DP, 0, sizeof (DP); DP [0] [7500] = 1; for (I = 1; I <= N; I ++) for (j = 1; j <= m; j ++) for (k = G [I] * C [J]; k <= 15000; k ++) DP [I] [k] + = DP [I-1] [k-G [I] * C [J]; printf ("% d \ n ", DP [N] [1, 7500]); Return 0 ;}