POJ 1837 Balance "DP"

Source: Internet
Author: User

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"

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.