lightoj 1085【离散化+树状数组】
来源:互联网 发布:浩顺考勤机数据库 编辑:程序博客网 时间:2024/05/29 23:48
题意:
求所有的上升子序列种数;
思路:
我想先离散化一下,然后用树状数组维护一下。
最终答案就是sum(n) ?
求所有的上升子序列种数;
思路:
我想先离散化一下,然后用树状数组维护一下。
最终答案就是sum(n) ?
卧槽,好像是;然后就过了。。
#include <bits/stdc++.h>using namespace std;typedef long long LL;const LL mod=1000000007;const int N=1e5+10;LL arr[N],n;LL c[N*4];void add(LL i,LL v){ while(i<=n) { c[i]=(c[i]+v)%mod; i+=i&(-i); }}LL Sum(LL i){ LL ans=0; while(i>0) { ans=(ans+c[i])%mod; i-=i&(-i); } return ans%mod;}vector<LL>xs;int main(){ int T,cas=1; scanf("%d",&T); while(T--) { scanf("%d",&n); xs.clear(); for(int i=1;i<=n;i++) { scanf("%lld",&arr[i]); xs.push_back(arr[i]); } sort(xs.begin(),xs.end()); vector<LL>::iterator e=unique(xs.begin(),xs.end()); for(int i=1;i<=n;i++) arr[i]=lower_bound(xs.begin(),e,arr[i])-xs.begin()+1; memset(c,0,sizeof(c)); LL temp; for(int i=1;i<=n;i++) { temp=(Sum(arr[i]-1)+1%mod); add(arr[i],temp); } printf("Case %d: %lld\n",cas++,Sum(n)); } return 0;}
0 0
- lightoj 1085【离散化+树状数组】
- lightoj 1085【离散化+树状数组】
- LightOJ-1085-树状数组,离散化,dp
- LightOJ 1085 All Possible Increasing Subsequences (DP&离散化&树状数组)
- lightoj 1085 All Possible Increasing Subsequences(递推式+离散化+树状数组维护)
- 树状数组--离散化
- lightoj 1085 树状数组+dp
- Flowers&&树状数组+离散化
- hdu4417(离散化+树状数组)
- POJ2299 树状数组+离散化
- poj2299 离散化+树状数组
- hdu4325 树状数组+离散化
- hdu5372 离散化+树状数组
- poj2299 树状数组+离散化
- poj2299离散化,树状数组
- hdu5862树状数组 离散化
- hdu5877dfs,树状数组离散化
- POJ2299 树状数组+离散化
- 2016 Unicode Conference拾遗(三)
- 算法概论 8.22
- 浅谈C/S端不同数据流无法同时传输问题
- gcc和g++编译器的区别
- php发送邮件
- lightoj 1085【离散化+树状数组】
- LeetCode 64. Minimum Path Sum
- 激励文
- C语言函数的参数和返回值
- JAVA动态代理原理(转)
- Java Thread到底有多快/慢?
- VS2013 c++/c编写的程序在别人的机子运行不了,缺少mfc100u.dll xxx100d.dll等的解决方法
- PHP 获取 post 中的 json 数据
- 2016广东工业大学第一次月赛 b题