Poj 2392 space elevator backpack question

Source: Internet
Author: User

Multiple backpacks. This question does not require binary optimization. Relatively simple. Because the number of duplicates is very small, less than 10;

Add a method to limit the height of each material. If you use reverse table filling, you only need to enter the table from this height to a small recursion.

In addition, pay attention to sorting, and sort by height restriction from small to large. Otherwise, the answer is incorrect.

# Include <stdio. h> # include <string. h ># include <algorithm> Using STD: sort; const int max_k = 401; const int max_h = 40001; struct HCA {int H, A, C; bool operator <(const HCA & HAC) {return a <HAC. A ;}}; HCA [max_k]; bool TBL [max_h]; inline int max (int A, int B) {return A> B? A: B;} int bagdp (int B) {memset (TBL, 0, sizeof (TBL); TBL [0] = true; For (INT I = 1; I <= B; I ++) {int K = 1; for (; (k <1) <= HCA [I]. c; k <= 1) {for (Int J = HCA [I]. a; j> = HCA [I]. H * k; j --) if (TBL [J-HCA [I]. H * k]) TBL [J] = true;} k = HCA [I]. c-k + 1; for (Int J = HCA [I]. a; j> = HCA [I]. H * k; j --) if (TBL [J-HCA [I]. H * k]) TBL [J] = true;} int I = max_h-1; for (; I> 0 &&! TBL [I]; I --); return I;} int main () {int blocks; scanf ("% d", & blocks); For (INT I = 1; I <= blocks; I ++) {scanf ("% d", & HCA [I]. h, & HCA [I]. a, & HCA [I]. c);} Sort (HCA, HCA + blocks + 1); printf ("% d \ n", bagdp (blocks); Return 0 ;}




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.