01 how to apply a backpack hdu1709

Source: Internet
Author: User
/* Question: give a few numbers as weights to see which cannot be claimed. Solution: first, find all the situations that can be added to the backpack, and then brute force find out the situations where subtraction can be used. When the variable I and j are put out, it will time out .... Thank you, Gigi. */# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> using namespace STD; int DP [11002]; int vis [11002]; int XX [11002]; int res [11002]; int A [112], sum, N, T; void onepack (INT cost, int weight) {int L; for (L = sum; L> = cost; l --) if (DP [l] <DP [L-cost] + weight) DP [l] = DP [L-cost] + weight;} int main () {int I, j; // timeout will occur when it is put out. Thank you for choosing Gigi. While (~ Scanf ("% d", & N) {memset (DP, 0, sizeof (DP); memset (VIS, 0, sizeof (VIS); sum = 0; for (I = 0; I <n; I ++) {scanf ("% d", & A [I]); sum + = A [I];} for (I = 0; I <n; I ++) onepack (A [I], a [I]); for (I = 1; I <= sum; I ++) vis [DP [I] = 1; t =-1; for (I = 1; I <= sum; I ++) if (vis [I]) xx [++ T] = I; for (I = 0; I <= T; I ++) for (j = I + 1; j <= T; j ++) vis [XX [J]-XX [I] = 1; t = 0; for (I = 1; I <= sum; I ++) if (! Vis [I]) {res [++ T] = I;} printf ("% d \ n", T); If (T> 0) {for (I = 1; I <t; I ++) printf ("% d", Res [I]); printf ("% d \ n ", res [T]) ;}} 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.