设$f(i, j)$表示以$i$结尾的,长为$j$的上升子序列的数量
转移时用树状数组维护即可
复杂度为$O(kn log n)$
注:特判0
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> namespace remoon { #define ri register int #define ll long long #define tpr template <typename ra> #define rep(iu, st, ed) for(ri iu = st; iu <= ed; iu ++) #define drep(iu, ed, st) for(ri iu = ed; iu >= st; iu --) #define gc getchar inline int read() { int p = 0, w = 1; char c = gc(); while(c > '9' || c < '0') { if(c == '-') w = -1; c = gc(); } while(c >= '0' && c <= '9') p = p * 10 + c - '0', c = gc(); return p * w; } int wr[50], rw; #define pc(iw) putchar(iw) tpr inline void write(ra o, char c = ' ') { if(!o) pc('0'); if(o < 0) o = -o, pc('-'); while(o) wr[++ rw] = o % 10, o /= 10; while(rw) pc(wr[rw --] + '0'); pc(c); } } using namespace std; using namespace remoon;
#define sid 100050 int n, k, a[sid]; ll t[sid][12]; inline void upd(int o, ll v, int k) { for(ri i = o; i <= n + 1; i += i & (-i)) t[i][k] += v; } inline ll qry(int o, int k) { ll ret = 0; for(ri i = o; i; i -= i & (-i)) ret += t[i][k]; return ret; } inline void DP() { ll ans = 0; if(k == 0) ans = 1; rep(i, 1, n) { upd(a[i], 1, 1); rep(j, 2, k + 1) { ll S = qry(a[i] - 1, j - 1); if(j == k + 1) { ans += S; break; } upd(a[i], S, j); } } write(ans); } int main() { n = read(); k = read(); rep(i, 1, n) a[i] = read() + 1; DP(); return 0; }