# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
19324 |
2016-02-24T09:44:29 Z |
cki86201 |
Ω (kriii4_P3) |
C++14 |
|
0 ms |
1816 KB |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int, int> Pi;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
const ll MOD = 1e9 + 7;
ll pw(ll a,ll b){
a %= MOD;
ll res = 1;
while(b){
if(b&1)res = (res * a) % MOD;
a = (a * a) % MOD;
b >>= 1;
}
return res;
}
ll b[110];
ll M[110][110];
int main(){
int p, q, n, k;
scanf("%d%d%d%d", &p, &q, &n, &k);
if(k == 0)printf("0");
else if(k == n)printf("1");
else{
ll p1 = (q * pw(p, MOD-2)) % MOD;
ll p2 = (MOD + 1 - p1) % MOD;
for(int i=1;i<n;i++){
M[i][i] = 1;
if(i != n)M[i][i+1] = (MOD - p2) % MOD;
if(i != 1)M[i][i-1] = (MOD - p1) % MOD;
}
b[n-1] = p2;
--n;
for(int i=1;i<=n;i++){
ll tmp = pw(M[i][i], MOD-2) % MOD;
for(int j=i;j<=n;j++){
M[i][j] = (M[i][j] * tmp) % MOD;
}
b[i] = (b[i] * tmp) % MOD;
for(int j=i+1;j<=n;j++){
if(M[i][j] == 0)continue;
ll mul = M[j][i];
for(int k=i;k<=n;k++)M[j][k] = ((M[j][k] - mul * M[i][k]) % MOD + MOD) % MOD;
b[j] = ((b[j] - mul * b[i]) % MOD + MOD) % MOD;
}
}
//for(int i=1;i<=n;i++){for(int j=1;j<=n;j++)printf("%lld ", M[i][j]);puts("");}
for(int i=n;i>=1;i--){
for(int j=i-1;j>=1;j--){
b[j] -= b[i] * M[j][i] % MOD;
b[j] = (b[j] + MOD) % MOD;
}
}
printf("%lld", b[k]);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1816 KB |
Output is correct |
2 |
Correct |
0 ms |
1816 KB |
Output is correct |
3 |
Correct |
0 ms |
1816 KB |
Output is correct |
4 |
Correct |
0 ms |
1816 KB |
Output is correct |
5 |
Correct |
0 ms |
1816 KB |
Output is correct |
6 |
Correct |
0 ms |
1816 KB |
Output is correct |
7 |
Correct |
0 ms |
1816 KB |
Output is correct |
8 |
Correct |
0 ms |
1816 KB |
Output is correct |
9 |
Correct |
0 ms |
1816 KB |
Output is correct |
10 |
Correct |
0 ms |
1816 KB |
Output is correct |
11 |
Correct |
0 ms |
1816 KB |
Output is correct |
12 |
Correct |
0 ms |
1816 KB |
Output is correct |
13 |
Correct |
0 ms |
1816 KB |
Output is correct |
14 |
Correct |
0 ms |
1816 KB |
Output is correct |
15 |
Correct |
0 ms |
1816 KB |
Output is correct |
16 |
Correct |
0 ms |
1816 KB |
Output is correct |
17 |
Correct |
0 ms |
1816 KB |
Output is correct |
18 |
Correct |
0 ms |
1816 KB |
Output is correct |
19 |
Correct |
0 ms |
1816 KB |
Output is correct |
20 |
Correct |
0 ms |
1816 KB |
Output is correct |
21 |
Correct |
0 ms |
1816 KB |
Output is correct |
22 |
Correct |
0 ms |
1816 KB |
Output is correct |
23 |
Correct |
0 ms |
1816 KB |
Output is correct |
24 |
Correct |
0 ms |
1816 KB |
Output is correct |
25 |
Correct |
0 ms |
1816 KB |
Output is correct |
26 |
Correct |
0 ms |
1816 KB |
Output is correct |
27 |
Correct |
0 ms |
1816 KB |
Output is correct |
28 |
Correct |
0 ms |
1816 KB |
Output is correct |
29 |
Correct |
0 ms |
1816 KB |
Output is correct |
30 |
Correct |
0 ms |
1816 KB |
Output is correct |