Topic Portal
Test instructions: Ask n-length sequence to find out the scheme number of the ascending sub-sequence of length m.
Analysis: This question is asked: dp[i][j] = SUM (Dp[i-1][k]) (1 <= k <= N, A[k] < a[j]), the current length I one layer, the last subscript J layer, before the last subscript K layer, this is the complexity of n^3. Then the tree array can optimize the complexity of the j,k, that is, J-Scan the same time, the A[j] information updated to the tree, then the scan can use Logn time to count the information of K, before this first to a[] discretization.
/************************************************* author:running_time* Created time:2015/10/21 Wednesday 13:20:36* Fi Le name:c.cpp ************************************************/#include <cstdio> #include <algorithm># Include <iostream> #include <sstream> #include <cstring> #include <cmath> #include <string > #include <vector> #include <queue> #include <deque> #include <stack> #include <list># Include <map> #include <set> #include <bitset> #include <cstdlib> #include <ctime>using namespace std; #define Lson L, Mid, RT << 1#define Rson mid + 1, R, RT << 1 | 1typedef long ll;const int N = 1e3 + 10;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;const Double EPS = 1e-8;st ruct BIT {int c[n], SZ; void Add (int &a, int b) {A + = B; while (a >= mod) A-= mod; } void init (int n) {memset (c, 0, sizeof (c)); SZ = n; } void updata (int i, int x) {while (I <= SZ) {Add (C[i], x); i + = i & (-i); }} int query (int i) {int ret = 0; while (i) {Add (ret, c[i]); I-= i & (-i); } return ret; }}bit;int A[n], a[n];int dp[n][n];void compress (int N) {sort (A, a+n); int nn = unique (A, a+n)-A; for (int i=0; i<n; ++i) {A[i] = Lower_bound (A, a+n, A[i])-A + 1; }}int Main (void) {int T, cas = 0; scanf ("%d", &t); while (t--) {int n, m; scanf ("%d%d", &n, &m); Bit.init (n); for (int i=0; i<n; ++i) {scanf ("%d", &a[i]); A[i] = A[i]; } compress (n); memset (DP, 0, sizeof (DP)); for (int i=0; i<n; ++i) dp[1][i] = 1; int ans = 0; for (int i=2; i<=m; ++i) {bit.init (n); for (int j=0; j<n; ++j) {Dp[i][j] = Bit.query (A[j]-1); Bit.updata (A[j], dp[i-1][j]); }} for (int i=0; i<n; ++i) bit.add (ans, dp[m][i]); printf ("Case #%d:%d\n", ++cas, ans); } return 0;}
Dp+bit (optimization complexity) UESTC 1217 the Battle of Chibi