First, according to the price from small to large sort, and then one by one to see if you can add in ...
Naked Quasi-array I'm going to qaq.
But to understand, you can think like this, is similar to the Gaussian elimination of the steps ... But the elimination of the elements is in order.
1 /**************************************************************2 problem:40043 User:rausen4 language:c++5 result:accepted6 time:812 Ms7 memory:2840 KB8 ****************************************************************/9 Ten#include <cstdio> One#include <cmath> A#include <algorithm> - - using namespacestd; thetypedefDoubleLF; - Const intN =505; - -InlineintRead () { + Static intx; - Static Charch; +x =0, ch =GetChar (); A while(Ch <'0'||'9'<ch) atCH =GetChar (); - while('0'<= CH && Ch <='9') { -x = x *Ten+ CH-'0'; -CH =GetChar (); - } - returnx; in } - toTemplate <classT>intsgn (T x) { + StaticT EPS = 1e-5; - if(Fabs (x) < EPS)return 0; the returnEPS >0?1: -1; * } $ Panax Notoginseng structData { - intC; the LF V[n]; + AInline lf&operator[] (inti) { the returnV[i]; + } - $Inlinevoid Get(intm) { $ Static inti; - for(i =1; I <= m; ++i) V[i] =read (); - } the -InlineBOOL operator< (ConstData &p)Const {Wuyi returnC <p.c; the } - } A[n]; Wu - intN, M; About intW[n], ans1, ans2; $ - intMain () { - intI, J, K; - LF tmp; An = Read (), M =read (); + for(i =1; I <= N; ++i) A[i].Get(m); the for(i =1; I <= N; ++i) a[i].c =read (); -Sort (A +1, A + n +1); $ the for(i =1; I <= N; ++i) the for(j =1; J <= M; ++J)if(SGN (a[i][j]) = =1) { the if(W[j]) { theTMP = A[i][j]/A[w[j]][j]; - for(k = j; k <= m; ++k) a[i][k]-= tmp *A[w[j]][k]; in}Else { theW[J] =i; the++ANS1, Ans2 + =a[i].c; About Break; the } the } theprintf"%d%d\n", ans1, ans2); + return 0; -}
View Code
BZOJ4004 [JLOI2015] Equipment purchase