Submission #19268

#TimeUsernameProblemLanguageResultExecution timeMemory
19268kaTkaHr제비 (kriii4_W)C++14
6 / 100
131 ms142176 KiB
#include <stdio.h> #include<vector> #include <algorithm> #include <map> using namespace std; typedef long long ll; const int MX = 3005, MM = 1000000007; ll pw(ll A, ll B){ ll R = 1; while(B){ if( B&1 ) R = R * A % MM; A = A * A % MM; B /= 2; } return R; } ll rv(ll A){ return pw(A, MM-2); } struct frac{ ll A, B; frac(ll A):A(A), B(1){} frac(ll a, ll b){ A = (a%MM+MM) % MM; B = (b%MM+MM) % MM; } 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 pw(frac A, ll B){ frac R = 1; while(B){ if( B&1 ) R = R * A; A = A * A; B /= 2; } return R; } frac P[MX][MX]; int main() { int R, G, B, K, T; int TT; scanf("%d", &TT); for(int tt = 1; tt <= TT; tt++){ scanf("%d%d%d%d", &R, &G, &B, &K); if( tt == 1 ){ for(int i = 0; i <= R; i++) P[i][1000] = 0; for(int i = R; i >= 0; i--){ for(int j = 999; j >= 0; j--){ int T = R + G + B - i; P[i][j] = P[i][j+1] * frac(B, T) + 1; if( i < R ) P[i][j] = P[i][j] + P[i+1][j] * frac(R-i, T); P[i][j] = P[i][j] * frac(T, T-G); } } printf("%lld\n", P[0][1000-K].v()); } else{ printf("%lld\n", P[0][1000-K].v()); } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...