Submission #19324

#TimeUsernameProblemLanguageResultExecution timeMemory
19324cki86201Ω (kriii4_P3)C++14
100 / 100
0 ms1816 KiB
#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 timeMemoryGrader output
Fetching results...