题意:

让你从所给的序列中找到他的子序列,使他们相邻之间差距不超过d,问有多少个转移的子序列

这题第一眼大概就知道是状态转移,sum[i]表示以前i个中有多少个,那么sum[i+1]比sum[i]

多了一个以第i+1为结尾的子序列,那么只需要知道前面当中以x(x与第i+1距离不超过d)结尾的子序列个数和,那么这个时候在用dp[x]表示当前以x结尾有多少个子序列,但是数字太大不能直接记录,直接求和.

所以需要在状态转移时候运用到一些技巧,树状数组(也可以用线段树)和离散化;

先读入所以数字,然后排序编号,并用树状数组维护

Description

For a set of sequences of integers{a1,a2,a3,...an}, we define a sequence{ai1,ai2,ai3...aik}in which 1<=i1<i2<i3<...<ik<=n, as the sub-sequence of {a1,a2,a3,...an}. It is quite obvious that a sequence with the length n has 2^n sub-sequences.
And for a sub-sequence{ai1,ai2,ai3...aik},if it matches the following qualities: k >= 2, and the neighboring 2 elements have the difference not larger than d, it will be defined as a Perfect Sub-sequence. Now given an integer sequence, calculate the number
of its perfect sub-sequence. 
 

Input

Multiple test cases The first line will contain 2 integers n, d(2<=n<=100000,1<=d=<=10000000) The second line n integers, representing the suquence
 

Output

The number of Perfect Sub-sequences mod 9901 
 

Sample Input

4 2
1 3 7 5
 

Sample Output

4
 
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<map>
#include<queue>
#include<vector> using namespace std;
const int maxn = 2e5+100;
const int MOD = 9901;
#define pr(x) cout << #x << " = " << x << " ";
#define prln(x) cout << #x << " = " << x <<endl;
#define ll long long ll cnt;
map<ll,ll> ID;
ll a[maxn],b[maxn],dp[maxn],n;
void getID(ll x) {
if(!ID.count(x)) {
ID[x] = ++cnt;
}
}
ll lowbit( ll x )
{
return x & (-x);
} void add(ll x,ll d)
{
while( x <= n)
{
dp[x] = (dp[x] + d)%MOD;;
x += lowbit(x);
}
} ll sum (ll x)
{
int ans = 0;
while(x)
{
ans = (ans + dp[x])%MOD;
x -= lowbit(x);
}
return ans%MOD;
} int main(){
#ifdef LOCAL
freopen("C:\\Users\\User Soft\\Desktop\\in.txt","r",stdin);
//freopen("C:\\Users\\User Soft\\Desktop\\out.txt","w",stdout);
#endif
ll d;
while( cin >> n >> d) {
ID.clear();cnt = 0;
memset(dp,0,sizeof dp);
for(int i = 0; i < n; ++i) {
scanf("%lld", &a[i]);
b[i] = a[i];
}
sort(b,b+n);
for(int i = 0; i < n; ++i) getID(b[i]);
for(int i = 0; i < n; i++) {
int l = lower_bound(b,b+n,a[i] - d) -b;
int r = upper_bound(b,b+n,a[i] + d) - b-1;
//if(r == l)
l = ID[b[l]],r = ID[b[r]];
ll num = (sum(r) - sum(l-1) +1)%MOD;
add(ID[a[i]],num );
}
cout << (sum(cnt) + 20*MOD- n)%MOD << endl; }
return 0;
}

HDU3450_Counting Sequences的更多相关文章

  1. [LeetCode] Repeated DNA Sequences 求重复的DNA序列

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

  2. [Leetcode] Repeated DNA Sequences

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

  3. 论文阅读(Weilin Huang——【AAAI2016】Reading Scene Text in Deep Convolutional Sequences)

    Weilin Huang--[AAAI2016]Reading Scene Text in Deep Convolutional Sequences 目录 作者和相关链接 方法概括 创新点和贡献 方法 ...

  4. leetcode 187. Repeated DNA Sequences 求重复的DNA串 ---------- java

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

  5. [UCSD白板题] Longest Common Subsequence of Three Sequences

    Problem Introduction In this problem, your goal is to compute the length of a longest common subsequ ...

  6. Python数据类型之“序列概述与基本序列类型(Basic Sequences)”

    序列是指有序的队列,重点在"有序". 一.Python中序列的分类 Python中的序列主要以下几种类型: 3种基本序列类型(Basic Sequence Types):list. ...

  7. Extract Fasta Sequences Sub Sets by position

    cut -d " " -f 1 sequences.fa | tr -s "\n" "\t"| sed -s 's/>/\n/g' & ...

  8. 【BZOJ-4059】Non-boring sequences 线段树 + 扫描线 (正解暴力)

    4059: [Cerc2012]Non-boring sequences Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 440  Solved: 16 ...

  9. MOOCULUS微积分-2: 数列与级数学习笔记 1. Sequences

    此课程(MOOCULUS-2 "Sequences and Series")由Ohio State University于2014年在Coursera平台讲授. PDF格式教材下载 ...

随机推荐

  1. 【读书笔记】:MIT线性代数(4):Independence, Basis and Dimension

    Independence: The columns of A are independent when the nullspace N (A) contains only the zero vecto ...

  2. 1.Jmeter 快速入门教程(一) - 认识jmeter和google插件

    Jmeter是免费开源的性能测试工具( 同时也可以用作功能测试,http协议debug工具 ).  在如今越来越注重知识产权的今天, 公司越来越不愿意冒着巨大的风险去使用盗版的商业性能测试工具. 但如 ...

  3. Linux环境下OpenSceneGraph的安装和配置

    1.在GitHub上下载OpenSceneGrpah的源码包,地址. 2.解压缩源码包并进入源码包; 3.安装所需的依赖库: 先输入命令: sudo apt-get install openscene ...

  4. leetcode.双指针.680验证回文字符串-Java

    1. 具体题目 给定一个非空字符串 s,最多删除一个字符.判断是否能成为回文字符串. 示例 1: 输入: "aba" 输出: True 示例 2: 输入: "abca&q ...

  5. 【知识强化】第五章 传输层 5.2 UDP协议

    这节课我们来学习一下UDP协议. 那在上节课呢我们学了这样一个打油诗. 啊,就是传输层有两个好兄弟,大哥TCP和二弟UDP.大哥很靠谱,二弟不靠谱.那只要说到UDP协议我们就要知道它的一个重要的特点, ...

  6. Web 请求之--性能相关

    本博客代码运行环境 python : Python 3.7.1rc1 version pip : pip 19.1.1 version Scrapy: scrapy 1.6.0 version asy ...

  7. rabbitmq一个连接多个信道channel

    https://www.cnblogs.com/eleven24/p/10326718.html

  8. Java线程的优先级设置遵循什么原则?

    Java线程的优先级设置遵从下述原则: (1) 线程创建时,子线程继承父线程的优先级 (2) 线程创建后,可在程序中通过调用setPriority( )方法改变线程的优先级 (3) 线程的优先级是1~ ...

  9. Jmeter 将正则表达式提取的参数传给全局(跨线程组使用变量)

    一.使用正则表达式提取sessionId 1.在测试计划(跨线程组使用变量)--> 线程组(登录)--> 添加HTTP请求(登录接口) (1)创建测试计划: 勾选独立运行每个线程组(例如在 ...

  10. js对象的深度拷贝

    //判断对象的类型 Array Object Function String Number ..... function getObjType(obj){ return Object.prototyp ...