UV 10154-weights and measures [DP] Qi

Source: Internet
Author: User

Question: Ultraviolet A 10154-Weights and Measures


Some turtles have a certain weight and strength. The greatest height and strength of the stack must bear all the weights above.


Analysis: sort by the power it can bring up from small to large

Then define DP [I] to indicate the minimum quality of the I-Turtles.

Next, the transfer is to find the minimum complexity of traversing O (n) each time, record and save the maximum value.


AC code:

# Include <iostream> # include <cstdio> # include <cstring> # include <cstdlib> # include <map> # include <cmath> # include <vector> # include <algorithm> using namespace STD; const int n = 10050; struct node {int W, POW ;}; vector <node> V; int CMP (node A, Node B) {if (. pow! = B. pow) return. pow <B. pow;} int DP [N]; // DP [I] selects the minimum weight int main () {node X; while (~ Scanf ("% d", & X. w, & X. pow) {X. pow-= x. w; V. push_back (x);} Sort (v. begin (), V. end (), CMP); memset (DP, 0x3f3f3f3f, sizeof (DP); int ans = 0; DP [0] = 0; For (INT I = 0; I <v. size (); I ++) {for (Int J = v. size ()-1; j> = 1; j --) {If (DP [J-1] <= V [I]. pow) DP [J] = min (DP [J], DP [J-1] + V [I]. w); If (DP [J] <1000000000) ans = max (J, ANS) ;}} printf ("% d \ n", ANS); V. clear (); Return 0 ;}


UV 10154-weights and measures [DP] Qi

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.