Hard to Compare

시간 제한4초메모리 제한9 MB

요약
각 테스트케이스의 n과 k에 대해 x가 1부터 k-1까지 변할 때 f(n,k,x)의 가장 큰 값 9개의 합을 1e9+7로 나눈 나머지를 구한다.
난이도

어려움10점 중 9점

유형
조합론, 수학, 동적 계획법
정답자
아직 제출이 없습니다

문제

Please pay attention to the unusual memory limit.

Let f(n,k,x)f(n, k, x), where n>k>x≥1n > k > x \ge 1, denote the number of integer arrays of length nn that contain integers from 11 to xx exactly once, contain integers from x+1x+1 to kk at least twice, and do not contain any other integers. For example, f(7,4,2)=840f(7,4,2) = 840, as there are 77 ways to place 11, then there are 66 ways to place 22, and there are 2020 ways to place 33 and 44 in the five remaining spots such that both 33 and 44 appear at least twice.

You are given integers nn and kk. Find the 99 largest values among f(n,k,1),f(n,k,2),…,f(n,k,k−1)f(n,k,1), f(n,k,2), \ldots, f(n,k,k-1), and print their sum modulo 109+710^9+7.

입력

The input contains one or more test cases. The first line contains the number of test cases tt (1≤t≤1061 \le t \le 10^6).

The only line of each test case contains two integers nn and kk (104≥n>k≥1010^4 \ge n > k \ge 10).

출력

For each test case, output one integer: the sum of 99 largest values modulo 109+710^9+7.

힌트

In the first test case, f(17,12,1)=f(17,12,2)=…=f(17,12,6)=0f(17,12,1) = f(17,12,2) = \ldots = f(17,12,6) = 0, so the answer is just the sum of the remaining nonzero values.

예제1

  1. 예제 1

    입력
    3
    17 12
    88 24
    6949 4513
    
    예상 출력
    567627977
    225618886
    360966919