dp+ tree-like array optimization.
DP[I][J] Indicates the number of schemes with a maximum rise sequence length of J, ending with A[i]. Dp[i][j]=sum{dp[k][j-1]} where k<i&&a[k]<a[i]. After discretization, it can be maintained with 1000 tree-like arrays.
#pragmaComment (linker, "/stack:1024000000,1024000000")#include<cstdio>#include<cstring>#include<cmath>#include<cstdlib>#include<algorithm>#include<vector>#include<map>#include<Set>#include<queue>#include<stack>#include<iostream>using namespaceStd;typedefLong LongLL;Const DoublePI = ACOs (-1.0), EPS = 1e-8;voidFile () {freopen ("D:\\in.txt","R", stdin); Freopen ("D:\\out.txt","W", stdout);} InlineintRead () {Charc = GetChar (); while(!isdigit (c)) C =GetChar (); intx =0; while(IsDigit (c)) {x = x *Ten+ C-'0'; c =GetChar ();} returnx;}intMod=1000000007;Const intmaxn=1010;intA[maxn],b[maxn],c[maxn][maxn],dp[maxn][maxn],ans;intt,n,m;intLowbit (intx) {returnx& (-x); }intSumintRintP) {intres=0; for(intI=p;i>0; I=i-lowbit (i)) res= (Res+c[r][i])%mod;returnRes;}voidUpdateintRintPintV) { for(inti=p;i<=1001; I=i+lowbit (i)) c[r][i]= (c[r][i]+v)%MoD;}intMain () {scanf ("%d", &t);intcas=1; while(t--) {scanf ("%d%d", &n,&m); Memset (c,0,sizeofc); ans=0; for(intI=1; i<=n;i++) scanf ("%d", &a[i]), b[i-1]=A[i]; Sort (b, B+ N);intSZ = unique (b, B + N)-b; for(intI=1; i<=n;i++) A[i]=lower_bound (b, B + sz, a[i])-b+2; for(intI=1; i<=n;i++) {dp[i][1]=1; Update1, a[i],dp[i][1]); for(intj=2; j<=m;j++) {Dp[i][j]=sum (J-1, a[i]-1); Update (J,A[I],DP[I][J]); } } for(intI=1; i<=n;i++) ans= (ans+dp[i][m])%MoD; printf ("Case #%d:%d\n", cas++, ans); } return 0;}
UESTC 1217 the Battle of Chibi