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个点只有从它的左下方格点可达,此时可获得收益.求该过程最大收益. 分析:我们很容易就可以想到用 ...
随机推荐
- 【计数】【UVA11401】 Triangle Counting
传送门 Description 把1……n这n个数中任取3个数,求能组成一个三角形的方案个数 Input 多组数据,对于每组数据,包括: 一行一个数i,代表前i个数. 输入结束标识为i<3. O ...
- shell中的数值运算
By francis_hao Oct 2,2017 本文摘录自bash的man手册. 算数运算相关的形式 形式 含义 ((expression)) expression按照下面描述的算术 ...
- hdu 5616
Jam's balance Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- Matrix.(POJ-2155)(树状数组)
题目是让每次对一个子矩阵进行翻转(0变1,1变0), 然后有多次询问,询问某个点是0还是1 这题可以用二维的树状数组来解决,考虑传统的树状数组是改变某个点,然后查询某一段, 而这个题是改变某一段,查询 ...
- ZOJ 3556 How Many Sets I
How Many Sets I Time Limit: 2 Seconds Memory Limit: 65536 KB Give a set S, |S| = n, then how ma ...
- PAT (Advanced level) 1003. Emergency (25) Dijkstra
As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...
- MSSQL Export Excel
输出Excel: -- To allow advanced options to be changed. GO -- To update the currently configured value ...
- SpringBoot jar包不支持jsp
官方原文如下: When running a Spring Boot application that uses an embedded servlet container (and is packa ...
- UIPageControl---iOS-Apple苹果官方文档翻译
本系列所有开发文档翻译链接地址:iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址 //转载请注明出处--本文永久链接:http://www.cnblogs.com/Ch ...
- Vue.js最佳实践(五招让你成为Vue.js大师)
对大部分人来说,掌握Vue.js基本的几个API后就已经能够正常地开发前端网站.但如果你想更加高效地使用Vue来开发,成为Vue.js大师,那下面我要传授的这五招你一定得认真学习一下了. 第一招:化繁 ...