给定两个整数n; k,求1; 2; 3; : : : ; n 的排列中,有k 对逆序对的排列的个数。
Input
本题有多组数据,每行两个整数n; k。最后一行为"0 0" 表示结束。
Output
对每组数据,输出一行一个整数,表示答案。
Sample Input
3 0
3 1
3 2
3 3
4 2
4 10
13 23
18 80
0 0
Sample Output
1
2
2
1
5
0
46936280
184348859235088
设f[i][j]为1-i之间,逆序对数量为j的方案数。
然后有这么一个性质:
序列1,3,2,5,4。(顺序可以乱,但还是这几个数),要插入一个6:
插在1前,得到5个新的逆数对;插在3前得到4个,插在2前得到3个…
OK.
然后这里的公式是:
k,即新增逆数对数量。
初始化f[1][0]=1.
然后加上高精。。。
#include<cstdio>
#include<iostream>
using namespace std;
int n,k,maxx;
int f[51][1501][103];
bool Z(){
scanf("%d%d",&n,&k);
if(n==0&&k==0) return 0;
int i