Test instructions: Give a balance, give the C hook, and the position of the C Hook Pos[i], give g weight, g weight of the quality w[i], asked when all the weights on the time, so that the balance of the plan number,
DP[I][J] Indicates the total number of scenarios when the balance point is J when the first I weight is hung.
Whether the state transfer is the first weight or not, if I want to hang the first weight, j>=pos[i]*w[i] (torque = arm force) because the maximum torque is 20*15*25=150000
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 7 intdp[ -][15000],pos[ -],w[ -];8 9 intMain ()Ten { One inti,j,k,c,g; A while(SCANF ("%d%d", &c,&g)! =EOF) - { - for(i=1; i<=c;i++) scanf ("%d", &pos[i]);//c hooks, the position of each hook the for(i=1; i<=g;i++) scanf ("%d", &w[i]);//g weights, quality of each weight -Memset (DP,0,sizeof(DP)); -dp[0][7500]=1;//when you are not hanging weights on both sides, the number of balanced schemes is 1 . - + for(i=1; i<=g;i++) - { + for(j=0; j<=15000; j + +) A { at for(k=1; k<=c;k++) - { - if(j>=pos[k]*W[i]) -dp[i][j]+=dp[i-1][j-pos[k]*W[i]]; - } - } in } -printf"%d\n", dp[g][7500]); to } + return 0; -}
View Code
Actually think this question indefinitely = = look at the problem, look at the code, think it is so, but again a fine thought, why can do it, J value is too big, print to see the value of the middle can not see =
Think again = =
go--go--
POJ 1837 Balance "DP"