hdu 2227(树状数组+dp)
Find the nondecreasing subsequences
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1844 Accepted Submission(s): 677
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 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.
each test case, output one line containing the number of nondecreasing
subsequences you can find from the sequence S, the answer should %
1000000007.
1 2 3
- #include <iostream>
- #include <stdio.h>
- #include <string.h>
- #include <stack>
- #include <vector>
- #include <algorithm>
- using namespace std;
- typedef long long LL;
- const int N = ;
- const int mod = ;
- int n;
- int a[N],b[N],c[N];
- int lowbit(int x){
- return x&(-x);
- }
- void update(int idx,int v){
- for(int i=idx;i<=n;i+=lowbit(i)){
- c[i]=(c[i]+v)%mod;
- }
- }
- int getsum(int idx){
- int sum = ;
- for(int i=idx;i>=;i-=lowbit(i)){
- sum = (sum+c[i])%mod;
- }
- return sum;
- }
- int main()
- {
- while(scanf("%d",&n)!=EOF){
- memset(c,,sizeof(c));
- for(int i=;i<=n;i++){
- scanf("%d",&a[i]);
- b[i] = a[i];
- }
- sort(b+,b++n);
- int ans = ;
- for(int i=;i<=n;i++){
- int idx = lower_bound(b+,b++n,a[i])-b;
- ans=getsum(idx);
- update(idx,ans+);
- }
- printf("%d\n",getsum(n));
- }
- return ;
- }
hdu 2227(树状数组+dp)的更多相关文章
- hdu 4991(树状数组+DP)
Ordered Subsequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- hdu 4638 树状数组 区间内连续区间的个数(尽可能长)
Group Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- hdu 4777 树状数组+合数分解
Rabbit Kingdom Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- hdu 4622 Reincarnation trie树+树状数组/dp
题意:给你一个字符串和m个询问,问你l,r这个区间内出现过多少字串. 连接:http://acm.hdu.edu.cn/showproblem.php?pid=4622 网上也有用后缀数组搞得. 思路 ...
- 2018 CCPC网络赛 1010 hdu 6447 ( 树状数组优化dp)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=6447 思路:很容易推得dp转移公式:dp[i][j] = max(dp[i][j-1],dp[i-1][j ...
- hdu 3030 Increasing Speed Limits (离散化+树状数组+DP思想)
Increasing Speed Limits Time Limit: 2000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java ...
- 【树状数组+dp】HDU 5542 The Battle of Chibi
http://acm.hdu.edu.cn/showproblem.php?pid=5542 [题意] 给定长为n的序列,问有多少个长为m的严格上升子序列? [思路] dp[i][j]表示以a[i]结 ...
- HDU 6348 序列计数 (树状数组 + DP)
序列计数 Time Limit: 4500/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Subm ...
- HDU 6447 YJJ’s Salesman (树状数组 + DP + 离散)
题意: 二维平面上N个点,从(0,0)出发到(1e9,1e9),每次只能往右,上,右上三个方向移动, 该N个点只有从它的左下方格点可达,此时可获得收益.求该过程最大收益. 分析:我们很容易就可以想到用 ...
随机推荐
- 怎么使用formBuilder以拖拽方式编写页面
1.以admin用户登录系统,打开formbuilder http://localhost:8081/framework/main/formbuilder 2.从右方组件中,用鼠标拖拽页面所需的组件到 ...
- 数据添加到solr索引库后前台如何搜索
主要结构: 查询 Dao: package com.taotao.search.dao.impl; import java.util.ArrayList; import java.util.List; ...
- SQLite 学习笔记
SQLite 学习笔记. 一.SQLite 安装 访问http://www.sqlite.org/download.html下载对应的文件. 1.在 Windows 上安装 SQLite. ...
- ACM2112迪克斯特算法
HDU Today Problem Description 经过锦囊相助,海东集团终于度过了危机,从此,HDU的发展就一直顺风顺水,到了2050年,集团已经相当规模了,据说进入了钱江肉丝经济开发区50 ...
- CSS知识之 background-position 用法详细介绍
一.语法 background-position : length || length background-position : position || position 二.取值 length ...
- C++ 指针常见用法小结
1. 概论 2.指针基础 3. 指针进阶 4. 一维数组的定义与初始化 5. 指针和数组 6. 指针运算 7. 多维数组和指针 8. 指针形参 9. 数组形参 10. 返回指针和数组 11. 结语 ...
- 11.nginx upload module + python django 后台 实现视频上传与切片
1.需求:支持视频上传并切片,支持通过m3u8文件播放 2.视频切片的上一节已经谈过,这一节主要是视频上传的处理 第一步:upload-module模块安装 -----------首先下载upload ...
- 数据结构:Bitset
这个东西看起来很棒棒的样子呀 bitset存储二进制数位 bitset就像一个bool类型的数组一样 bitset中的每个元素都能单独被访问 整数类型和布尔数组都能转化成bitset 有关Bitset ...
- HDU 5961 传递 BFS
题意:中文题,就是判断一个竞赛图拆成两个图,判断是否都传递 思路:分别BFS判深度即可,用这种方法注意要进行读入优化. /** @Date : 2016-11-18-20.00 * @Author : ...
- Redis 键值数据类型及基本操作
到目前为止,Redis 支持的键值数据类型如下: 字符串(String) 哈希(Map) 列表(list) 集合(sets) 有序集合(sorted sets) 1. String 字符串类型 s ...