problem 2236 14th targetProblem Description
The eyes of the police, Princess Miles, Dr. Agasa and other people in a succession of unknown identity of the person's plot, Conan tracking injury Dr. Agasa's murderer, according to several cases on the scene left clues found that the murderer in accordance with the sequence of playing cards. After a series of reasoning, Conan found that the names of the victims include the number of cards, and the size of poker is strictly increasing, in addition to the victim and the small Yogoro.
To avoid the appearance of the next victim, Conan ranked the number of people who might have been ambushed by relevance, that is, the order cannot be changed. Conan needs to know the total number of possible results, to meet the victim's name appears in the numbers are strictly increased, but he to find the key evidence, so this task is given to you.
(If you do not understand what is said above, the question is to find the number of Strictly ascending subsequence in a sequence.) For example, the sequence (1,3,2) of the strict increment subsequence has (1), (3), (2), (1,3), (five), a total of 5. A different sub-sequence, such as a sequence (3,3), that has the same length but different positions, is 2. )
Input
Multiple sets of data (<=10), processed to EOF.
The first line enters a positive integer n (n≤100 000), representing a total of n individuals.
The second line has a total of n integer Ai (1≤ai≤10^9), which represents the number in the first person name.
Output
Each set of data outputs an integer that represents all possible results. Since the result may be large, the output is modulo after 1 000 000 007.
Sample INPUT31 3 2 sample Output5
#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespacestd;Const intmaxn=1e5+5;Const intmod=1e9+7;structnode{intVal,id;} B[MAXN];intN;intID[MAXN],DP[MAXN];BOOLCMP (Node A,node b) {returna.val<B.val;}intLowbit (intx) {returnx& (-x);}voidUpdateintPosintval) { while(pos<=N) {Dp[pos]+=Val; Dp[pos]%=MOD; POS+=Lowbit (POS); }}intQueryintx) { intres=0; while(x) {res+=Dp[x]; Res%=MOD; X-=lowbit (x); } returnRes;}intMain () { while(SCANF ("%d", &n)! =EOF) {memset (DP,0,sizeof(DP)); for(intI=1; i<=n;i++) { intT; scanf ("%d",&t); B[i].val=T; B[i].id=i; } sort (b+1, b+n+1, CMP); intCnt=1; b[0].val=b[1].val; for(intI=1; i<=n;i++) { if(b[i].val==b[i-1].val) id[b[i].id]=CNT; ElseId[b[i].id]=++CNT; } for(intI=1; i<=n;i++) Update (Id[i],query (Id[i )-1)+1); printf ("%d\n", query (n)); } return 0;}
Fzuoj Problem 2236 14th target (tree-like array +dp)