poj_1837

dp[i][j]
用前i个砝码,使"力矩"大小为j的情况数量
极端情况下,20个重量为25的砝码,都挂在距离中心点-15的位置,得到力矩是-7500
所以,让j=7500时为平衡状态

 1 #include <cstdio>

 2 #include <cstring>

 3 

 4 #define MAXN 20

 5 

 6 int C, G, dp[MAXN+1][2*MAXN*15*25+1], hook[MAXN+1], weight[MAXN+1];

 7 

 8 int main(int argc, char const *argv[])

 9 {

10     // freopen("in", "r", stdin);

11     scanf("%d%d", &C, &G);

12     for(int i = 1; i <= C; ++i)

13         scanf("%d", &hook[i]);

14     for(int i = 1; i <= G; ++i)

15         scanf("%d", &weight[i]);

16 

17     // initialize

18     memset(dp, 0 ,sizeof(dp));

19     dp[0][7500] = 1;

20 

21     // dp

22     for(int i = 1; i <= G; ++i)

23         for(int j = 0; j <= 15000; ++j)

24             if(dp[i-1][j])

25                 for(int k = 1; k <= C; ++k)

26                     dp[i][ j+hook[k]*weight[i] ] += dp[i-1][j];

27 

28     printf("%d\n", dp[G][7500]);

29     return 0;

30 }

 

你可能感兴趣的:(poj)