<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      HDU 2227 Find the nondecreasing subsequences (DP+樹狀數組+離散化)

      題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=2227

                              Find the nondecreasing subsequences

                                       Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
                                                          Total Submission(s): 1442    Accepted Submission(s): 516

      Problem Description

      How many nondecreasing subsequences can you find in the sequence S = {s1, s2, s3, ...., sn} ? For example, we assume that S = {1, 2, 3}, and you can find seven nondecreasing subsequences, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}. 

      Input

      The input consists of multiple test cases. Each case begins with a line containing a positive integer n that is the length of the sequence S, the next line contains n integers {s1, s2, s3, ...., sn}, 1 <= n <= 100000, 0 <= si <= 2^31. 

      Output

      For each test case, output one line containing the number of nondecreasing subsequences you can find from the sequence S, the answer should % 1000000007. 

      Sample Input

      3

      1 2 3

      Sample Output

      7

       

      題目分析

      題目大意:給你一個串,求這個串中不遞減的子串有多少個?初一看,完全想不到會是用樹狀數組,但是他就是這么神奇,不遞減就想到逆序數,逆序數又想到了樹狀數組,居然是用他。他是求子串有多少個,又要用到DP,這里DP就是用樹狀數組慢慢推上去,最后是注意是求和會溢出,記得%1000000007

       

       

       1 #include<iostream>
       2 #include<stdio.h>
       3 #include<memory.h>
       4 #include<algorithm>
       5 
       6 using namespace std ;
       7 
       8 struct node 
       9 {
      10     int val, id ;
      11 }a[100005];
      12 
      13 bool cmp(node a, node b)
      14 {
      15     return a.val < b.val ;
      16 }
      17 
      18 int b[100005] , c[100005] , s[100005] ,n ;
      19 
      20 int lowbit( int  i)
      21 {
      22     return i&(-i);
      23 }
      24 
      25 void update ( int i , int x )
      26 {
      27     while(i<=n)
      28     {
      29         s[i]+=x;
      30         if(s[i]>=1000000007)
      31             s[i]%=1000000007;
      32         i+=lowbit(i);
      33     }
      34 }
      35 
      36 int sum( int i )
      37 {
      38     int sum = 0 ;
      39     while( i > 0 )
      40     {
      41         sum += s[i] ;
      42         if( sum >= 1000000007)
      43             sum %= 1000000007;
      44         i-=lowbit( i ) ;
      45     }
      46     return sum ;
      47 }
      48 
      49 
      50 
      51 int main()
      52 {
      53     int i , res ;
      54     while(scanf("%d",&n)!=EOF)
      55     {
      56         memset( b , 0 , sizeof(b)) ;
      57         memset( s , 0 , sizeof(s)) ;
      58         for(i=1;i<=n;i++)
      59         {
      60             scanf("%d",&a[i].val);
      61             a[i].id = i ;
      62         }
      63         sort(a+1,a+n+1,cmp);
      64         b[a[1].id] = 1 ;
      65         for(i=2;i<=n;i++)
      66         {
      67             if(a[i].val!=a[i-1].val)
      68                 b[a[i].id] = i ;
      69             else b[a[i].id] = b[a[i-1].id] ;
      70         }
      71         res = 0 ;
      72         for(i=1;i<=n;i++)
      73         {
      74             c[i] = sum( b[i] ) ;
      75             update ( b[i] , c[i]+1 ) ;
      76         }
      77         printf("%d\n",sum(n));
      78     }
      79     return 0 ;
      80 }
      View Code

       

      posted @ 2014-08-15 19:54  四十四次日落  Views(272)  Comments(0)    收藏  舉報
      主站蜘蛛池模板: 2020国产欧洲精品网站| 超清无码一区二区三区| 亚洲国产成人资源在线| 亚洲免费最大黄页网站| 精品一区二区亚洲国产| 麻豆国产成人av高清在线| 日韩高清不卡免费一区二区| 日韩有码国产精品一区| 欧美叉叉叉bbb网站| 蜜桃av多人一区二区三区| 91偷自国产一区二区三区| 福利网午夜视频一区二区| 精品无码国产日韩制服丝袜| 国产一精品一av一免费| 亚洲精品成人区在线观看| 国产福利社区一区二区| 韩国深夜福利视频在线观看| 国产精品自在欧美一区| 国产美女午夜福利视频| 国产亚洲精品视频一二区| 成年女人免费视频播放体验区| 虎白女粉嫩尤物福利视频| 蜜桃网址| 亚洲中文字幕一区二区| 精品一区二区中文字幕| 成人国产精品一区二区网站公司| 国产精品午夜福利导航导| 国产免费一区二区不卡| 日本一卡2卡3卡四卡精品网站| 精品国产综合成人亚洲区| 亚洲国产精品久久久久4婷婷| 精品久久久久无码| 久久亚洲中文字幕伊人久久大| 国产高清一区二区不卡| 亚洲av高清一区二区| 人妻va精品va欧美va| 亚洲卡1卡2卡3精品| 亚洲日本精品一区二区| 亚洲成人av在线高清| 开心五月激情综合久久爱| 日韩剧情片电影网站|