Topic Portal: QWQ
Analysis
Test instructions: Give a series, ask how many five Yuan rise group
Consider simplifying the question: if the topic asks for a two-dollar ascent group, what to do.
In reverse order, use a tree-like array to maintain the OK.
Ternary how to do it?
The expansion of the two yuan to one, that is, the third is also thrown into a tree array
So the problem is becoming clearer:
With $ dp[i][x] $ for $ a[x] $ to end the $ x $ $ Rise Group has how many
So:
$ dp[i][x]=\sum_{j=1}^{i-1} Dp[j][x-1] (A[j]<a[i]) $
Where $ dp[i][1]=1 $
Because there's a big one, plus one.
But this looks like $ O (n^2) $, definitely cool, so throw it into a tree-like array to optimize for a bit.
Well, the problem is also discrete and highly accurate.
Code
#include <cstdio>#include<algorithm>#include<cstring>using namespacestd;Const intmaxn=50010, N =50010, Base =10000000; typedefLong LongLL;classBignum { Public: intnum[7], Len; Bignum (): Len (0) {} bignum (intN): Len (0) { for(; n >0; n/= Base) num[len++] = n%Base; } bignum bigvalueof (LL N) {len=0; while(n) {num[len++] = n%base; N/=Base; } return* This; } bignumoperator+ (Constbignum&b) {bignum C; intI, carry =0; for(i =0; I < This->len | | I < B.len | | Carry >0; ++i) {if(I < This->len) Carry + = This-Num[i]; if(I < B.len) Carry + =B.num[i]; C.num[i]= Carry%base; Carry/=Base; } C.len= i;returnC; } bignumoperator+= (Constbignum& b) {* This= * This+ b;return* This; } voidPrint () {if(len = =0) {puts ("0");return ;} printf ("%d", Num[len-1]); for(inti = len-2; I >=0; --i) for(intj = base/Ten; J >0; J/=Ten) printf ("%d", num[i]/j%Ten); Puts (""); }};typedef bignum bign;intn;bign sum[maxn][8]; structnode{intV,pos; BOOL operator< (Constnode& a)Const{returnv<a.v;}} A[MAXN];voidAddintXintE,bign a) { for(; x<=n;x+=x&-x) sum[x][e]+=A;} Bign Summ (intXinte) {bign ans; for(;x>0; x-=x&-x) ans+=sum[x][e];returnans;}intMain () { while(~SCANF ("%d",&N)) { for(intI=1; i<=n;i++) {scanf ("%d", &A[I].V); a[i].pos=i;} Sort (a+1, A +1+N); memset (SUM,0,sizeof(sum)); intCnt=0; Bign ans=0; for(intI=1; i<=n;i++) {Add (A[i].pos,1,1); for(intj=2; j<=5; j + +) {Add (A[i].pos,j,summ (A[i].pos-1, J-1)); }} summ (N,5). Print (); } return 0;}
"POJ" 3378 Crazy thairs (tree-like array +dp+ high-precision)