Poj-3624 charm bracelet

Source: Internet
Author: User

01 backpack, DP short answer on the line, to use a rolling array, or the memory to burst. The direction of the For Loop is very important. Although it is a simple question, it helps a lot to understand DP,

I tried to write every status according to the team leader, which is easier to understand.

1 # include <stdio. h> 2 # include <string. h> 3 # define doumax (A, B) (A> B? A: B) 4 const int maxn = 3500, maxm = 13000; 5 Int W [maxn], d [maxn], DP [maxm]; 6 int main () 7 {8 int n, m; 9 While (scanf ("% d", & N, & M) = 2) {10 for (INT I = 1; I <= N; I ++) 11 scanf ("% d", & W [I], & D [I]); 12 memset (DP, 0, sizeof (DP); 13 for (INT I = 1; I <= N; I ++) 14 for (Int J = m; j> 0; j --) {15 if (j> = W [I]) 16 DP [J] = doumax (DP [J], DP [J-W [I] + d [I]); 17} 18 printf ("% d \ n", DP [m]); 19} 20 return 0; 21}

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.