#P15569. [COCI 2025/2026 #5] 结构 / Struktura

    ID: 17433 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>动态规划 DPO2优化矩阵加速COCI(克罗地亚)2026

[COCI 2025/2026 #5] 结构 / Struktura

Background

The full score for this problem is 110110.

Problem Description

Petar and Ivana felt bored on a long winter afternoon, so they invented a number game.

Petar randomly writes down nn numbers on paper. Each number is chosen independently and uniformly from 11 to kk, forming an array aa.

Ivana says she especially likes some arrays because they have a kind of “hidden balance”. She calls such arrays structures (structure). The array aa is a structure if and only if the following conditions are satisfied:

  • The integers 1,2,…,n1,2,\dots,n each appear in the array exactly once.
  • For every index ii (1≤i≤n1 \le i \le n), we have ∣ai+i−n−1∣≤1|a_i + i - n - 1| \le 1.

Ivana wants to know: when Petar generates the array aa completely at random, what is the probability that it is a structure.

It can be proven that the answer can always be written as a fraction PQ\dfrac{P}{Q}, where PP is an integer, and QQ is a positive integer that is not divisible by 109+710^9+7.

Input Format

One line contains two non-negative integers n,kn,k (1≤n,k≤1091 \le n,k \le 10^9).

Output Format

Output one integer, representing the required probability modulo 109+710^9+7.

2 1
0
2 2
500000004
7 94
100976822

Hint

Sample Explanation

Explanation for Sample #2:

There are 22=42^2=4 possible arrays Petar can write: (1,1),(1,2),(2,1),(2,2)(1,1),(1,2),(2,1),(2,2). Among them, the structures are (1,2)(1,2) and (2,1)(2,1). The probability is 24\dfrac{2}{4}, so the output is 2⋅4−1 mod (109+7)=5000000042 \cdot 4^{-1} \bmod (10^9+7)=500000004.

Subtasks

Subtask Score Limits
11 1717 n,k≤7n,k \le 7
22 2323 n≤7n \le 7, k≤100k \le 100
33 1919 n≤20n \le 20, k≤100k \le 100
44 2525 n,k≤106n,k \le 10^6
55 2626 No additional limits

Translated by ChatGPT 5