Algorithm topic--Dynamic programming

Source: Internet
Author: User

1.poj1837:balance

Core code:

Base point set dp[0][7500]=1;

1  for (int k=1; k<=g;k++)             2      for (int j=0; j<n;j++) 3          for (int i=1; i<=c;i++)     4             dp[k][j+moment[i][k]]=dp[k][j+moment[i][k]]+dp[k-1][j];

Moment[i][k]: The moment of the first k weight in position I

Obviously K stands for weights, I stands for position, J is for traversing the entire DP table

Understand the meaning of the DP transfer equation: DP[K][J] Indicates the number of cases where the moment is J when using the first K weights

Obviously the outermost loop is K, the internal two layers can obviously be reversed, without effect (the values of the lower layer plus the upper layer, do not interfere with each other)

Algorithm topic--Dynamic programming

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.