Problem Description
You were driving along a highway when you got caught by the road police for speeding. It turns out that they\'ve been following you, and they were amazed by the fact that you were accelerating the whole time without using the brakes! And now you desperately need an excuse to explain that.

You've decided that it would be reasonable to say "all the speed limit signs I saw were in increasing order, that\'s why I've been accelerating". The police officer laughs in reply, and tells you all the signs that are placed along the segment of highway you drove, and says that's unlikely that you were so lucky just to see some part of these signs that were in increasing order.

Now you need to estimate that likelihood, or, in other words, find out how many different subsequences of the given sequence are strictly increasing. The empty subsequence does not count since that would imply you didn't look at any speed limits signs at all!

For example, (1, 2, 5) is an increasing subsequence of (1, 4, 2, 3, 5, 5), and we count it twice because there are two ways to select (1, 2, 5) from the list.

 
Input
The first line of input gives the number of cases, N. N test cases follow. The first line of each case contains n, m, X, Y and Z each separated by a space. n will be the length of the sequence of speed limits. m will be the length of the generating array A. The next m lines will contain the m elements of A, one integer per line (from A[0] to A[m-1]).

Using A, X, Y and Z, the following pseudocode will print the speed limit sequence in order. mod indicates the remainder operation.

for i = 0 to n-1
print A[i mod m]
A[i mod m] = (X * A[i mod m] + Y * (i + 1)) mod Z

Note: The way that the input is generated has nothing to do with the intended solution and exists solely to keep the size of the input files low.

1 ≤ m ≤ n ≤ 500 000

 
Output
For each test case you should output one line containing "Case #T: S" (quotes for clarity) where T is the number of the test case and S is the number of non-empty increasing subsequences mod 1 000 000 007.
 
Sample Input
2
5 5 0 0 5
1
2
1
2
3
6 2 2 1000000000 6
1
2
 
Sample Output
Case #1: 15 Case #2: 13

大致题意:

  求上升子序列的个数

  序列怎么出来的呢,好难懂:

    for i = 0 to n-1
    print A[i mod m]
    A[i mod m] = (X * A[i mod m] + Y * (i + 1)) mod Z

  取m=3为例 输入完a[] 以后,a[]不是序列 要按照他的循环 打印 a[0] ,a[1], a[2],a[0],a[1],a[2]....如此,每打印一个做一次A第三行的变换,最后就是0 -> n-1 的序列了。

解题思路:

  树状数组+离散化。

  动规求法: dp[i]=∑dp[j](j<i&&ans[j]<ans[i])

  依据树状数组快速统计可加类区间数据的应用,

  可转化成 dp[i]=sum(f[i]-1)+1 ;即以前f[i]-1个数据为底的个数再加上自身。

 #include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define N 500005
#define mod 1000000007
long long c[N],a[N],b[N],f[N],T,n,m,x,y,z,ans,size;
void modify(int x,int num){while(x<=n)c[x]+=num,c[x]%=mod,x+=x&-x;}
long long sum(int x){int s=;while(x>)s+=c[x],s%=mod,x-=x&-x;return s;}
void ini(){
memset(c,,sizeof(c));
ans=;
scanf("%d%d%lld%lld%lld",&n,&m,&x,&y,&z);
for(int i=;i<m;i++) scanf("%lld",&a[i]);
for(int i=;i<n;i++){
f[i]=b[i+]=a[i%m];
a[i%m]=(x*a[i%m]+y*(i+))%z;
}
}
int main(){
scanf("%d",&T);
for(int K=;K<=T;K++)
{
ini();
sort(b+,b+n+);//离散化
size=unique(b+,b+n+)-(b+);
for(int i=;i<n;i++){
int p=lower_bound(b+,b+size+,f[i])-b;
long long tot=sum(p-)+;
ans+=tot;
ans%=mod;
modify(p,tot);
} printf("Case #%d: %lld\n",K,ans);
} return ;
}

HDU 3030 - Increasing Speed Limits的更多相关文章

  1. hdu 3030 Increasing Speed Limits (离散化+树状数组+DP思想)

    Increasing Speed Limits Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java ...

  2. Increasing Speed Limits

    Increasing Speed Limits Time Limit: 2000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...

  3. hdu FatMouse's Speed 动态规划DP

    动态规划的解决方法是找到动态转移方程. 题目地址:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=3&sectionid ...

  4. HDU FatMouse's Speed 基本DP

    题意:要求找到的体重递增,速度递减的老鼠,并且输出最长的长度数,而且输出各自的序列数.Special Judge 思路:先按体重由小到大排序,再找最长速度递减序列. 转移方程:mou[i].w> ...

  5. hdu 3030

    这道题主要就是问你,长度为n的序列,有多少种上升的子序列 当前点的情况种数等于前面所有小于它的点的种数相加 + 1 1就是只有这一个点的时候的序列 那就是要多次查询前面比它小的点的种数的和 那么就是区 ...

  6. HDU 6852 Increasing and Decreasing 构造

    题意: 给你一个n,x,y.你需要找出来一个长度为n的序列,使得这个序列满足最长上升子序列长度为x,最长下降子序列长度为y.且这个序列中每个数字只能出现一次 且要保证最后输出的序列的字典序最小 题解: ...

  7. HDU题解索引

    HDU 1000 A + B Problem  I/O HDU 1001 Sum Problem  数学 HDU 1002 A + B Problem II  高精度加法 HDU 1003 Maxsu ...

  8. POJ 3653 &amp; ZOJ 2935 &amp; HDU 2722 Here We Go(relians) Again(最短路dijstra)

    题目链接: PKU:http://poj.org/problem? id=3653 ZJU:problemId=1934" target="_blank">http ...

  9. HDU 2722 Here We Go(relians) Again (spfa)

    Here We Go(relians) Again Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/ ...

随机推荐

  1. 浅谈postMessage多页面监听事件

    最近做了一个Echarts和Highcharts多图多页面连动的效果,就用到postMessage 如下介绍: 最开始在最外围的页面也就是所有页面的父级页面添加postMessage监听事件以便监听下 ...

  2. 未找到具有固定名称“System.Data.SQLite”的 ADO.NET 提供程序的实体框架提供程序

    用户代码未处理 System.InvalidOperationException   HResult=-2146233079   Message=未找到具有固定名称"System.Data. ...

  3. JavaScript模块化开发&&模块规范

    在做项目的过程中通常会有一些可复用的通用性功能,之前的做法是把这个功能抽取出来独立为一个函数统一放到commonFunctions.js里面(捂脸),实现类似于snippets的代码片段收集. fun ...

  4. Hibernate 查询:HQL查询(Hibernate Query Languge)

    HQL是一种面向对象的查询语言,其中没有表和字段的概念,只有类,对象和属性的概念. 使用HQL查询所有学生: public static void main(String[] args) { Sess ...

  5. 获得创建临时表的session id

    通过sql server的default trace和tempdb中的sys.objects视图,你能够获得创建临时表的session id,下面是相应的sql语句: DECLARE @FileNam ...

  6. 对获取config文件的appSettings节点简单封装

    转:http://www.cnblogs.com/marvin/archive/2011/07/29/EfficiencyAppSetting.html C#的开发中,无论你是winform开发还是w ...

  7. 我们为什么要遵循W3C标准规范

    大部分的站长和拥有网站的企业负责人都会知道,每当有浏览器发布大更新的时候,我们刚建立不久的网站就会发生无法预知的严重错误,我们只能重新建立或改版网站,使其可以应归新发布的浏览器.好比1996-1999 ...

  8. 初始seajs

    SeaJS是一个遵循CommonJS规范的JavaScript模块加载框架,可以实现JavaScript的模块化开发及加载机制 SeaJS本身遵循KISS(Keep It Simple, Stupid ...

  9. HTML5动画图片播放器 高端大气

    我们见过很多图片播放插件(焦点图),很多都基于jQuery.今天介绍的HTML5图片播放器很特别,它不仅在图片间切换有过渡动画效果,而且在切换时图片中的元素也将出现动画效果,比如图中的文字移动.打散. ...

  10. WDLINUX (Centos5.8) 安装 bcmath

    环境 centos5.8 php5.2.17 因为wdos 集成的php5.2.17为精简版,并未包含php52-bcmath扩展. 所以先下载完整php5.2.17源码包 wget -c http: ...