专栏名称: 每日一道算法题
学习算法是一种信仰,每天都需要坚持!
目录
相关文章推荐
算法与数学之美  ·  二级教授、大学原副校长,国务院特殊津贴获得者 ... ·  16 小时前  
算法与数学之美  ·  丘成桐任首任院长!顶尖大学成立新学院:8年制 ... ·  16 小时前  
九章算法  ·  Cruise被迫裁员50%!高额遣散费打脸科 ... ·  2 天前  
九章算法  ·  一年被裁两次,一个底层码农的大落大起 ·  2 天前  
51好读  ›  专栏  ›  每日一道算法题

629. K Inverse Pairs Array

每日一道算法题  · 公众号  · 算法  · 2017-08-22 20:25

正文

Given two integers n and k, find how many different arrays consist of numbers from 1 to n such that there are exactly k inverse pairs.


We define an inverse pair as following: For ith and jth element in the array, if i < j and a[i] > a[j] then it’s an inverse pair; Otherwise, it’s not.


Since the answer may be very large, the answer should be modulo 109 + 7.


Example 1:

Input: n = 3, k = 0

Output: 1

Explanation:

Only the array [1,2,3] which consists of numbers from 1 to 3 has exactly 0 inverse pair.

Example 2:

Input: n = 3, k = 1

Output: 2

Explanation:

The array [1,3,2] and [2,1,3] have exactly 1 inverse pair.

Note:

The integer n is in the range [1, 1000] and k is in the range [0, 1000].


提示 提交代码后 需要用简洁的语言解释一下代码思路 ~ 谢谢


历史题目和总结见公众号「每日一道算法题」


https://leetcode.com/problems/k-inverse-pairs-array/description/


题目解析









请到「今天看啥」查看全文