# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
19246 |
2016-02-22T13:53:33 Z |
kaTkaHr |
Ω (kriii4_P3) |
C++14 |
|
31 ms |
1428 KB |
#include <stdio.h>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
const int MX = 105, MM = 1000000007;
ll rv(ll A){
ll R = 1, B = MM-2;
while(B){
if( B&1 ) R = R * A % MM;
A = A * A % MM; B /= 2;
}
return R;
}
struct frac{
ll A, B;
frac(ll A, ll B):A(A), B(B){}
frac(){A = 0, B = 1;}
frac operator+ (const frac &l)const{
return frac((A * l.B + B * l.A) % MM, B * l.B % MM);
}
frac operator*(const frac &l)const{
return frac(A*l.A % MM, B*l.B % MM);
}
frac operator/(const frac &l)const{
return frac(A*l.B % MM, B*l.A % MM);
}
frac operator- (const frac &l)const{
return frac((A*l.B - B*l.A%MM + MM) % MM, B*l.B % MM);
}
ll v(){ return A * rv(B) % MM; }
};
frac D[MX][MX], I[MX][MX];
int P, Q, N, K;
void print()
{
for(int i = 1; i <= N; i++){
for(int j = 1; j <= N; j++){
printf("%lld,%lld ", D[i][j].A, D[i][j].B);
}
printf("\n");
}
printf("\n");
}
int main()
{
scanf("%d%d%d%d", &P, &Q, &N, &K);
for(int i = 0; i <= N; i++){
D[i][i] = I[i][i] = frac(1, 1);
if( i <= N-2 ) D[i][i+1] = frac(MM-Q, P);
if( i >= 2) D[i][i-1] = frac(MM-P+Q, P);
}
for(int i = 0; i <= N; i++){
for(int j = i+1; j <= N; j++){
frac p = D[j][i] / D[i][i];
for(int k = 0; k <= N; k++){
D[j][k] = D[j][k] - D[i][k] * p;
I[j][k] = I[j][k] - I[i][k] * p;
}
}
}
for(int i = N; i >= 0; i--){
for(int j = i-1; j >= 0; j--){
frac p = D[j][i] / D[i][i];
for(int k = N; k >= 0; k--){
D[j][k] = D[j][k] - D[i][k] * p;
I[j][k] = I[j][k] - I[i][k] * p;
}
}
}
for(int i = 0; i <= N; i++){
frac p = frac(1, 1) / D[i][i];
for(int j = 0; j <= N; j++){
D[i][j] = D[i][j] * p;
I[i][j] = I[i][j] * p;
}
}
printf("%lld", I[N][K].v());
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
1428 KB |
Output is correct |
2 |
Correct |
0 ms |
1428 KB |
Output is correct |
3 |
Correct |
30 ms |
1428 KB |
Output is correct |
4 |
Correct |
21 ms |
1428 KB |
Output is correct |
5 |
Correct |
13 ms |
1428 KB |
Output is correct |
6 |
Correct |
8 ms |
1428 KB |
Output is correct |
7 |
Correct |
5 ms |
1428 KB |
Output is correct |
8 |
Correct |
2 ms |
1428 KB |
Output is correct |
9 |
Correct |
0 ms |
1428 KB |
Output is correct |
10 |
Correct |
2 ms |
1428 KB |
Output is correct |
11 |
Correct |
17 ms |
1428 KB |
Output is correct |
12 |
Correct |
0 ms |
1428 KB |
Output is correct |
13 |
Correct |
12 ms |
1428 KB |
Output is correct |
14 |
Correct |
31 ms |
1428 KB |
Output is correct |
15 |
Correct |
0 ms |
1428 KB |
Output is correct |
16 |
Correct |
30 ms |
1428 KB |
Output is correct |
17 |
Correct |
0 ms |
1428 KB |
Output is correct |
18 |
Correct |
29 ms |
1428 KB |
Output is correct |
19 |
Correct |
0 ms |
1428 KB |
Output is correct |
20 |
Correct |
31 ms |
1428 KB |
Output is correct |
21 |
Correct |
1 ms |
1428 KB |
Output is correct |
22 |
Correct |
29 ms |
1428 KB |
Output is correct |
23 |
Correct |
0 ms |
1428 KB |
Output is correct |
24 |
Correct |
6 ms |
1428 KB |
Output is correct |
25 |
Correct |
11 ms |
1428 KB |
Output is correct |
26 |
Correct |
12 ms |
1428 KB |
Output is correct |
27 |
Correct |
3 ms |
1428 KB |
Output is correct |
28 |
Correct |
7 ms |
1428 KB |
Output is correct |
29 |
Correct |
3 ms |
1428 KB |
Output is correct |
30 |
Correct |
28 ms |
1428 KB |
Output is correct |