Light oj 1085 - All Possible Increasing Subsequences (简单dp + 离散化 + BIT)
2016-10-09 17:18
351 查看
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1085
题意:
问你有多少个上升子序列。
思路:
dp[i]表示以第i个数结尾的上升序列数量。
题意:
问你有多少个上升子序列。
思路:
dp[i]表示以第i个数结尾的上升序列数量。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <map> 6 using namespace std; 7 typedef long long LL; 8 const int N = 1e5 + 5; 9 int a ; 10 int b , n; 11 LL bit , mod = 1e9 + 7; 12 LL dp ; 13 14 void add(int i, LL val) { 15 for( ; i <= n; i += (i&-i)) 16 bit[i] += val; 17 } 18 19 LL sum(int i) { 20 LL s = 0; 21 for( ; i >= 1; i -= (i&-i)) 22 s += bit[i]; 23 return s; 24 } 25 26 int main() 27 { 28 int t; 29 scanf("%d", &t); 30 for(int ca = 1; ca <= t; ++ca) { 31 scanf("%d", &n); 32 for(int i = 1; i <= n; ++i) { 33 scanf("%d", a + i); 34 b[i] = a[i]; 35 } 36 sort(b + 1, b + n + 1); 37 memset(bit, 0, sizeof(bit)); 38 memset(dp, 0, sizeof(dp)); 39 for(int i = 1; i <= n; ++i) { 40 a[i] = lower_bound(b + 1, b + n + 1, a[i]) - b; 41 dp[i]++; 42 } 43 for(int i = 1; i <= n; ++i) { 44 dp[i] += sum(a[i] - 1); 45 dp[i] %= mod; 46 add(a[i], dp[i]); 47 } 48 LL ans = 0; 49 for(int i = 1; i <= n; ++i) { 50 ans += dp[i]; 51 ans %= mod; 52 } 53 printf("Case %d: %lld\n", ca, ans); 54 } 55 return 0; 56 }
相关文章推荐
- LightOJ 1085 - All Possible Increasing Subsequences(DP + 线段树 + 离散)
- LightOJ 1085 - All Possible Increasing Subsequences (离散化+树状数组+dp)
- Light OJ 1085 - All Possible Increasing Subsequences
- LightOJ 1085 All Possible Increasing Subsequences (DP&离散化&树状数组)
- lightoj 1085 - All Possible Increasing Subsequences 【树状数组优化dp】
- [树状数组]LightOJ 1085 - All Possible Increasing Subsequences
- Lightoj 1085 All Possible Increasing Subsequences (树状数组+DP)
- 1085 - All Possible Increasing Subsequences[树状数组]
- lightoj1085 - All Possible Increasing Subsequences(树状数组)
- lightoj1085 All Possible Increasing Subsequences
- HDU4570----Multi-bit Trie----简单的DP
- str_find_all_low_bit.py
- ZOJ 3349 Special Subsequence 简单DP + 线段树
- hdu 2227 Find the nondecreasing subsequences【离散化+树状数组+DP思路】
- if ( document.all ) 可以简单的判断浏览器是否IE浏览器?
- 使用Redis bitmaps进行快速、简单、实时统计
- Bit-Map算法的简单实现
- OpenStack Swift All In One安装部署流程与简单使用
- HDU 2836 Traversal 简单DP + 树状数组
- Crazy Test: How much time will be consume to exhaustive 16 bits numeral for all possible?