#P2612. [ZJOI2012] 波浪

    ID: 1625 远端评测题 6000ms 128MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>动态规划,dp2012各省省选浙江组合数学

[ZJOI2012] 波浪

Description

Amoeba and Xiaoqiang are good friends.

They are watching the waves by the sea. It is Xiaoqiang’s first time facing such surging tides, and he keeps shouting with excitement. Amoeba, however, remains calm, recalling the ups and downs of his career and the setbacks in his relationships... In short, compared with the storms he has experienced, today’s waves are nothing.

Thus, a disagreement between the two friends is inevitable. To support his view, Xiaoqiang builds a model. He abstracts the sea surface as a permutation P1NP_{1 \ldots N} of 11 to NN. Define the wave intensity as the sum of the absolute differences between adjacent elements, that is:

$$L = | P_2 - P_1 | + | P_3 - P_2 | + \ldots + | P_N - P_{N-1} |.$$

Given NN and MM, what is the probability that a uniformly random permutation of 1N1 \ldots N has wave intensity at least MM?

Output the answer rounded to KK digits after the decimal point.

Input Format

The first line contains three integers N,MN, M and KK, denoting the length of the permutation, the wave intensity threshold, and the number of digits to output, respectively.

Output Format

Output one real number with exactly KK digits after the decimal point.

3 3 3
0.667

Hint

For N=3N = 3, there are 66 permutations: 123,132,213,231,312,321123, 132, 213, 231, 312, 321; their wave intensities are 2,3,3,3,3,22, 3, 3, 3, 3, 2. Therefore, the probability that the wave intensity is at least 33 is 46\frac 46, i.e., 0.6670.667.

You can also verify this probability with the following code:

int a[3]={0,1,2},s=0,n=3;
for (int i=0;i<1000000;i++){
random_shuffle(a,a+n);
int t=0;
for (int j=0;j<n-1;j++) t+=abs(a[j+1]-a[j]); 
if (t>=3) s++;
}
printf("%.3f\n",s/1000000.0);

Constraints

For 100%100\% of the testdata, 0M21474836470 \leq M \leq 2147483647.

Please note that there is no single test point where both NN and KK reach their maximum values.

Test set index NN \le KK \le
131 \sim 3 1010 3030
464 \sim 6 100100 33
797 \sim 9 88
1010 5050 3030

Translated by ChatGPT 5