Topic Link: http://oj.xjtuacm.com/problem/14/"Analysis" two yuan in reverse order should be asked, you can use a tree-like array. This problem requires K-yuan, we can be regarded as two yuan. We first seek two yuan reverse logarithm,
And then for each number you can find the number of smaller numbers behind this number. And then we add a dollar, now sweep to A[i], then in the tree array, for those larger than his number of the inverse of the logarithm + = on the inverse logarithm of a dollar a[i].
#include <bits/stdc++.h>#defineMet (b) memset (a,b,sizeof a)#definePB Push_back#defineLson l,m,rt<<1#defineRson m+1,r,rt<<1|1#defineLowbit (x) (x& (×))using namespaceStd;typedefLong Longll;ll MoD= 1e9+7;Const intn=2e4+ -;Const intm=n*n+Ten;intN,m,k,a[n];ll Tre[n],ans1[n],ans2[n];voidAddintx,ll s) { while(x<=N) {Tre[x]+=s; TRE[X]%=MoD; X+=lowbit (x); }}ll Sum (intx) {LL ret=0; while(x>0) {ret+=Tre[x]; RET%=MoD; X-=lowbit (x); } returnret;}intMain () {intu,v; intT; scanf ("%d",&T); while(t--) {scanf ("%d%d",&n,&k); for(intI=1; i<=n;i++) scanf ("%d", &a[i]), ans2[i]=1; if(m==1) {printf ("%d\n", n);Continue; } for(intt=2; t<=k;t++){ for(intI=1; i<=n;i++) ans1[i]=ans2[i],ans2[i]=tre[i]=0; for(inti=n;i>=1; i--) {Ans2[a[i]]=Sum (A[i]); Add (A[i],ans1[a[i]]); }} ll ans=0; for(intI=1; i<=n;i++) ans= (Ans+ans2[i])%MoD; printf ("%lld\n", ans); } return 0;}
Xjtuoj Wmq's Team (tree-like array to find K-yuan reverse order)