forked from matthewsamuel95/ACM-ICPC-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpermutation_with_k_inversion.cpp
More file actions
73 lines (67 loc) · 965 Bytes
/
permutation_with_k_inversion.cpp
File metadata and controls
73 lines (67 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include<bits/stdc++.h>
using namespace std;
const long int p=1000000007;
int f[505][250005]={},g[505][250005]={};
long int perwithinv(int n,int k)
{
long int sum=0;
cout << n << " " << k << "\n";
if(k!=0&&n!=0)
{
for(int i=k;k>=0;k--)
{
sum=sum+perwithinv(n-1,i);
f[n][k]=sum;
cout << sum << "=sum\n";
return sum;
}
}
else
{
if(n==0)
{
return 0;
}
if(k==0)
{
cout << "----\n";
return 1;
}
}
}
int make_g(int x, int y)
{
if(y==0)
{
g[x][0]=perwithinv(x,0);
return f[x][0];
}
else
{
cout << make_g(x,y-1)<< "======++\n";
g[x][y]=make_g(x,y-1)+perwithinv(x,y);
cout << g[x][y] << "=g[][]\n";
return g[x][y];
}
}
long int fact(int n)
{
long int facto=1;
if(n==1||n==0)
return 1;
else
facto=(facto*fact(n-1))%p;
return facto;
}
int main()
{
int t,k;
cin >> t >> k;
int i;
long int sum1=0;
for(i=1;i<=t;i++)
{
sum1=(sum1+(make_g(i,k)*fact(t)*(t-i+1))%p)%p;
}
cout << sum1;
}