Inverse

Inverse

The inverse of permutation  (p1,p2,,pn)  is the number of pairs  (i,j)  which  i<j  and  pi>pj .

Count the number of permutaion of  {1,2,,n} , whose inverse is  k .

Input

Two integers  n k .

(1n100,0kn(n1)2)

Ouptut

An integer denotes the numbers of permutaions modulo  (109+7) .

Sample input

2 1

Sample output

1


基础动态规划。关键是想清楚n个排列数与n-1个排列数的递推关系。


计dp[x][y]:  表示x个数所组成的逆序个数为y的个数。 

那么状态转移方程为:dp[x][y+k]+=dp[x-1][k],  0<=k<=x-1.


#include <cmath>
#include <ctime>
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
#include <stack>
#include <deque>
using namespace std;
typedef long long LL;
#define eps 10e-9
#define inf 0x3f3f3f3f
const int maxn = 100000+100;
int dp[110][10000];
int main(){
    dp[1][0]=1;  dp[1][1]=0;

    for(int i=2;i<=100;i++){
        for(int j=0;j<=(i-1)*(i-2)/2;j++){
          for(int k=0;k<=i-1;k++)
          dp[i][j+k]=(dp[i][j+k]+dp[i-1][j])%(1000000000+7);
        }
    }
    int n,k;
    while(scanf("%d %d",&n,&k)!=EOF){
        printf("%d\n",dp[n][k]);

    }



    return 0;
}























































评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值