MiYu原创, 转帖请注明 : 转载自 ______________白白の屋  

题目地址:

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): 211    Accepted Submission(s): 80

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

题目分析:

整整一天的时间, 终于是把这个题A了  ,HDU 第一,  纪念下.....................

1 HUT-MiYu 375MS 1824K 2358B G++

2010-08-27 09:44:32

但也没有什么值得高兴的,  题目的思路是 小A 的,  0rz.......................  现在还是没有理解树状数组是怎么解这一题的,  它的思路是怎样的,

一点也没明白,   刚开始做的时候, 还以为 输入数据已经是按非递减排序了, 所以直接用 公式 2^n - 1, WA ...

.....  问过小A 才发现, 输入数据是 随机的.  这时就要像找上升子串一样, 找到它 所有的上升子串.  这里用到了 树状数组, 继续理解-ing......

先发代码 :

/*
MiYu原创, 转帖请注明 : 转载自 ______________白白の屋
http://www.cnblog.com/MiYu
Author By : MiYu
Test      : 1
Program   : 2227 
*/
#include <iostream>
#include <algorithm>
using namespace std;
#define lowbit(x) (x&(-x))
int num[100005];
int numcopy[100005];
int hash[100005];
int com[100005];
int nCount = 1;
void add ( int x,int k )
{
while ( x <= nCount )
{
com[x] += k;
if ( com[x] >= 1000000007 ) com[x] %= 1000000007;
x += lowbit(x); 
}
int sum ( int x )
{
int s = 0;
while ( x > 0 )
{
s += com[x];
if ( s >= 1000000007 ) s %= 1000000007;
x -= lowbit(x);
return s %= 1000000007;
}
int cmp (const void *a, const void *b)
{
return *((int*)a) - *((int*)b); 
}
int sfind ( int x )
{
int *p = (int *)bsearch ( &x,hash+1,nCount+1,sizeof ( int ),cmp ); 
return p - hash;
}
int find(int num){
int top=1,bottom=nCount,mid=(top+bottom)/2,ans=mid;
while(num!=hash[ans]){
if(hash[mid]<=num){
top=(ans=mid)+1;
}else{
bottom=mid-1;
}
mid=(top+bottom)/2;
}
return ans;
}
inline bool scan_d(int &num)  //整数输入
{
char in;bool IsN=false;
in=getchar();
if(in==EOF) return false;
while(in!='-'&&(in<'0'||in>'9')) in=getchar();
if(in=='-'){ IsN=true;num=0;}
else num=in-'0';
while(in=getchar(),in>='0'&&in<='9'){
num*=10,num+=in-'0';
}
if(IsN) num=-num;
return true;
}
int main ()
{
int N;
while ( scan_d ( N ) )
{
for ( int i = 0; i != N; ++ i )
scan_d ( num[i] ),numcopy[i] = num[i];
sort ( num, num + N );
memset ( com,0,sizeof (com) );
nCount = 1;
hash[1] = num[0];
for ( int i = 1; i < N; ++ i )
{
if ( num[i] != num[i-1] )
hash[++nCount] = num[i]; 
for ( int i = 0; i < N; ++ i )
{
int pos = find ( numcopy[i] ); 
int res = sum ( pos ) + 1;
add ( pos,res );
}
cout << sum ( nCount ) << endl;
}
return 0;
}

转载于:https://www.cnblogs.com/MiYu/archive/2010/08/27/1809842.html

HDOJ 2227 HDU 2227 Find the nondecreasing subsequences ACM 2227 IN HDU相关推荐

  1. HDOJ 1010 HDU 1010 Tempter of the Bone ACM 1010 IN HDU

    MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目描述: 代码 ...

  2. HDOJ 2066 HDU 2066 一个人的旅行 ACM 2066 IN HDU

    MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址:          http://acm.hdu.edu.cn/showproblem.php?pid=2066 ...

  3. HDOJ 1157 HDU 1157 Who's in the Middle ACM 1157 IN HDU

    MiYu原创, 转帖请注明 : 转载自 ______________白白の屋   题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1157 题目描述: ...

  4. HDOJ 1874 HDU 1874 畅通工程续 ACM 1874 IN HDU

    MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址:          http://acm.hdu.edu.cn/showproblem.php?pid=1874 ...

  5. HDOJ HDU 2080 夹角有多大II ACM 2080 IN HDU

    MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址:          http://acm.hdu.edu.cn/showproblem.php?pid=2080 ...

  6. HDOJ 1213 HDU 1213 How Many Tables ACM 1213 IN HDU

    MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址:          http://acm.hdu.edu.cn/showproblem.php?pid=1213 ...

  7. HDOJ 1016 HDU 1016 Prime Ring Problem ACM 1016 IN HDU

    题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1016 题目描述: Prime Ring Problem Time Limit: 4000/2000 ...

  8. HDOJ 1253 HDU 1253 胜利大逃亡 ACM 1253 IN HDU

    MiYu原创, 转帖请注明 : 转载自 ______________白白の屋   题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1253 题目描述: ...

  9. HDOJ HDU 1106 排序 ACM 1106 IN HDU

    //MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址 :             http://acm.hdu.edu.cn/showproblem.php?pi ...

最新文章

  1. 离职交接文档_如何写好离职工作交接文档?
  2. 04.full_text match查询
  3. mysql分页存储过程 分页查询语句_分页存储过程(用存储过程实现数据库的分页代码)...
  4. ksu7对讲机调频软件_数字对讲机的群呼功能原理是什么?你了解多少?
  5. c语言图像函数怎么用,请教 怎么才能用C输出一个函数的图像?大侠 帮帮忙啊...
  6. java参数传递时,究竟传递的是什么
  7. 为什么说劝人报名IT培训班的人,不是坏就是蠢?
  8. Python高阶——argparse(命令行与参数解析)
  9. linux虚拟机系统安装
  10. NAT,代理服务器技术
  11. Codeforces Round #444 (Div. 2)-贪心尺取-Ratings and Reality Shows
  12. 敏捷项目管理 第2版[JimHighsmith](一)
  13. “浅尝”JavaScript设计模式
  14. logcat查询日志
  15. 基础语法值c++提高编程
  16. 利用TrinityCore 框架的搭建魔兽世界私服
  17. 5G网络的NSA与SA
  18. 计算机丢了文件游戏打不开,你好360检测说我电脑文件缺失现在我电脑里游戏客户端打不开了怎么办...
  19. 粒子群算法之01背包问题(C语言实现)
  20. 《小群效应》徐志斌踢馆,分享疫情下的私域流量新机遇

热门文章

  1. yarn界面中的Minimum Allocation和Maximum Allocation与yarn-site.xml中参数的对应关系
  2. pyspark的rdd直接写入mysql
  3. notebook中安装lightgbm的gpu版本
  4. Master PDF editor在ubuntu下面的配置
  5. 大话数据结构 队列10:数组循环队列
  6. NoSQL, Clojure
  7. 机器学习(十八)——关联规则挖掘
  8. cron 12点执行_Linux中得循环调度任务执行
  9. 华为S系列交换机全面阻击“WannaCry”
  10. c#简单自定义异常处理日志辅助类