http://www.lightoj.com/volume_showproblem.php?problem=1085
Test Instructions: the number of ascending subsequence sequences for a sequence.
idea: to find the law can be found that a number as the number of the end of the type of the number of all smaller than its case +1. Use a tree-like array to find it. C++11 Auto is not available on Lightoj/.\
/** @Date: 2016-12-01-21.58 * @Author: Lweleth ([email protected]) * @Link: https://github.com/* @Versi On: */#include <bits/stdc++.h> #define LL long long#define PII pair<int,int> #define MP (x, y) Make_pair ((x), (Y )) #define FI first#define se second#define PB (x) push_back ((x)) #define MMG (x) memset ((x), -1,sizeof (x)) #define MMF (x) mem Set ((x), 0,sizeof (x)) #define MMI (x) memset ((x), INF, sizeof (x)) using namespace Std;const int INF = 0x3f3f3f3f;const int N = 1e5+20;const int mod = 1000000007;int C[n], a[n];void Add (int p, int v) {while (P < N) {C[p] + = V; C[P]%= mod; p + = (-P) & p; }}int sum (int p) {int ans = 0; while (p) {ans + = c[p]; Ans%= MoD; P-= (-P) & p; } return ans; int main () {int T; int cnt = 0; Cin >> T; while (t--) {MMF (C); int n; scanf ("%d", &n); Map<int, int>q; for (int i = 1; I <= n; i++) { scanf ("%d", &a[i]); Q[a[i]] = 1; } int c = 1; for (Auto i = Q.begin (); I! = Q.end (); i++) I->se = c + +; /*map<int, int>::iterator it; for (it = Q.begin (); It! = Q.end (); it++) It->se = c++;*/for (int i = 1; I <= n; i++)//Find the law to find a number As the number of species of the end number for all cases smaller than its number +1 {int x = q[a[i]]; Add (x, sum (x-1) + 1); } printf ("Case%d:%d\n", ++cnt, SUM (c-1)); } return 0;}
Lightoj 1085-all Possible increasing subsequences tree array + discrete