#P13465. [GCJ 2008 #1C] Increasing Speed Limits

    ID: 15340 远端评测题 6000ms 1024MiB 尝试: 0 已通过: 0 难度: 4 上传者: 标签>动态规划 DP2008树状数组Google Code Jam

[GCJ 2008 #1C] Increasing Speed Limits

题目描述

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)(1, 2, 5) is an increasing subsequence of (1,4,2,3,5,5)(1, 4, 2, 3, 5, 5), and we count it twice because there are two ways to select (1,2,5)(1, 2, 5) from the list.

输入格式

The first line of input gives the number of cases, NN. NN test cases follow. The first line of each case contains nn, mm, XX, YY and ZZ each separated by a space. nn will be the length of the sequence of speed limits. mm will be the length of the generating array AA. The next mm lines will contain the mm elements of AA, one integer per line (from A[0]A[0] to A[m1]A[m-1]).

Using AA, XX, YY and ZZ, 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.

输出格式

For each test case you should output one line containing "Case #TT: SS" (quotes for clarity) where TT is the number of the test case and SS is the number of non-empty increasing subsequences mod 1 000 000 0071\ 000\ 000\ 007.

2
5 5 0 0 5
1
2
1
2
3
6 2 2 1000000000 6
1
2
Case #1: 15
Case #2: 13

提示

Sample Explanation

The sequence of speed limit signs for case 22 should be 1,2,0,0,0,41, 2, 0, 0, 0, 4.

Limits

  • 1N201 \leq N \leq 20
  • 1m1001 \leq m \leq 100
  • 0X1090 \leq X \leq 10^9
  • 0Y1090 \leq Y \leq 10^9
  • 1Z1091 \leq Z \leq 10^9
  • 0A[i]<Z0 \leq A[i] < Z

Small dataset (15 Pts, Test set 1 - Visible)

  • 1mn10001 \leq m \leq n \leq 1000

Large dataset (35 Pts, Test set 2 - Hidden)

  • 1mn5000001 \leq m \leq n \leq 500000