冒泡排序计数
Description
考虑冒泡排序的一种实现。
bubble-sort (A[], n)
> round = 0
> while A is not sorted
> > round := round + 1
> > for i := 1 to n - 1
> > > if (A[i] > A[i + 1])
> > > > swap(A[i], A[i + 1])
求1 .. n的排列中,有多少个排列使得A被扫描了K遍,亦即算法结束时round == K。
答案模20100713输出。
Input
输入包含多组数据。每组数据为一行两个整数N,K。
Output
对每组数据,输出一行一个整数表示答案。
Sample Input 1
3
3 0
3 1
3 2
Sample Output 1
1
3
2
Hint
HINT:时间限制:1.0s 内存限制:256.0MB
T <= 10 ^ 5。
1 <= K < N < 10 ^ 6。
AC代码:
#include <cstdio>
#include <iostream>
using namespace std;
const int mod = 20100713;
typedef long long ll;
const