Hdu 2844 Coins (multiple backpacks)

Source: Internet
Author: User

The question is to give you a few numbers, then give you the available numbers, and then randomly find a few numbers to accumulate,

 


Let me calculate the number that can be accumulated!

 


Solution: First initialize the backpack to-1, calculate it with multiple backpacks, and finally search for it. If bb [I] = I, it means that I can get this number! The number of records that can be reached by a cyclic computing task is ready for output!

 


# Include <stdio. h>

# Define max (a, B) a> B? A: B


Int bb [500000];
Int vv;


Void shun (int cost, int weight)
{
Int I;
For (I = cost; I <= vv; I ++)
Bb [I] = max (bb [I], bb [I-cost] + weight );
}


Void ni (int cost, int weight)
{
Int I;
For (I = vv; I> = cost; I --)
Bb [I] = max (bb [I], bb [I-cost] + weight );
}


Int main ()
{
Int n, I, k, v [5000], amount [5000], ans;
While (scanf ("% d", & n, & vv), n + vv)
{
For (I = 1; I <= vv; I ++)
Bb [I] =-1;
For (I = 0; I <n; I ++)
Scanf ("% d", & v [I]);
For (I = 0; I <n; I ++)
Scanf ("% d", & amount [I]);
For (I = 0; I <n; I ++)
{
If (amount [I] * v [I]> = vv)
Shun (v [I], v [I]);
Else
{
K = 1;
While (k <amount [I])
{
Ni (k * v [I], k * v [I]);
Amount [I]-= k;
K * = 2;
}
Ni (amount [I] * v [I], amount [I] * v [I]);
}
}
Ans = 0;
For (I = 1; I <= vv; I ++)
If (bb [I] = I)
Ans ++;
Printf ("% d \ n", ans );
}
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.