//*
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<algorithm>
#include<vector>
#define all(A) (A).begin(), (A).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MN = 100+10;
const ll mod = 1000000007;
ll mpow(ll a,ll p){
ll r=1;
while(p>0){
if(p&1)r=r*a%mod;
a=a*a%mod;
p>>=1;
}
return r;
}
ll inv(ll a){
return mpow(a,mod-2);
}
int N,K;
ll A[MN][MN];
ll tmp[MN];
ll iN;
int main(){
scanf("%d%d",&N,&K);
if(N==1)return !printf("1\n");
iN=inv(N);
for(int i=0;i<N;i++){
if(i>0)A[i][i-1]=i*inv(N)%mod;
A[i][i]=-1;
A[i][i+1]=(N-i)*inv(N)%mod;
A[i][N+1]=-1;
}
A[N][N]=1;
A[N][N+1]=0;
for(int i=0;i<=N;i++){
if(A[i][i]==0){
int p=-1;
for(int j=i+1;j<=N;j++)if(A[j][i]==1)p=j;
for(int j=0;j<=N+1;j++)swap(A[i][j],A[p][j]);
}
ll iv=inv(A[i][i]);
for(int j=i;j<=N+1;j++){
A[i][j]=A[i][j]*iv%mod;
}
for(int k=i+1;k<=N;k++){
ll r=A[k][i];
for(int j=i;j<=N+1;j++){
A[k][j]=A[k][j]-r*A[i][j];
A[k][j]%=mod;
}
}
}
for(int i=N;i>0;i--){
for(int k=i-1;k>=0;k--){
ll r=A[k][i];
A[k][i]-=r*A[i][i];
A[k][i]%=mod;
A[k][N+1]-=r*A[i][N+1];
A[k][N+1]%=mod;
}
}
for(int i=N-1;i>=0;i--){
ll ans=A[i][N+1];
ans%=mod;
ans=(ans+mod)%mod;
printf("%lld\n",ans);
}
return 0;
}
//*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1176 KB |
Output is correct |
2 |
Correct |
1 ms |
1176 KB |
Output is correct |
3 |
Correct |
0 ms |
1176 KB |
Output is correct |
4 |
Correct |
0 ms |
1176 KB |
Output is correct |
5 |
Correct |
2 ms |
1176 KB |
Output is correct |
6 |
Correct |
0 ms |
1176 KB |
Output is correct |
7 |
Correct |
0 ms |
1176 KB |
Output is correct |
8 |
Correct |
0 ms |
1176 KB |
Output is correct |
9 |
Correct |
0 ms |
1176 KB |
Output is correct |
10 |
Correct |
0 ms |
1176 KB |
Output is correct |
11 |
Correct |
0 ms |
1176 KB |
Output is correct |
12 |
Correct |
1 ms |
1176 KB |
Output is correct |
13 |
Correct |
0 ms |
1176 KB |
Output is correct |
14 |
Correct |
0 ms |
1176 KB |
Output is correct |
15 |
Correct |
0 ms |
1176 KB |
Output is correct |
16 |
Correct |
0 ms |
1176 KB |
Output is correct |
17 |
Correct |
0 ms |
1176 KB |
Output is correct |
18 |
Correct |
0 ms |
1176 KB |
Output is correct |
19 |
Correct |
0 ms |
1176 KB |
Output is correct |
20 |
Correct |
0 ms |
1176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
1176 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |