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