제출 #1139416

#제출 시각아이디문제언어결과실행 시간메모리
1139416THXuanUzastopni (COCI15_uzastopni)C++20
0 / 160
1096 ms2632 KiB
// dp[i][j] = the number of ways if consider the first i people and j people get colored paintings /* * transition * dp[i][j] = ((dp[i-1][j-1] * a[i]) +(dp[i-1][j]* b[i])) % MOD; */ #include <iostream> #include <vector> #include <algorithm> #include <queue> #include <set> #include <map> #define INF 1e9 typedef long long ll; using namespace std; const ll MOD = 10007; ll dp[100005][25]; void solve() { int n, c; cin >> n >> c; vector<ll>a(n + 1), b(n + 1); for (int i = 1; i <= n; i++)cin >> a[i]; for (int i = 1; i <= n; i++)cin >> b[i]; int q; cin >> q; while (q--) { ll p, A, B; cin >> p >> A >> B; a[p] = A; b[p] = B; dp[1][0] = b[1]; dp[1][1] = a[1]; for (int i = 2; i <= n; i++) { for (int j = 0; j <= i; j++) { if (j == 0) dp[i][j] = (dp[i - 1][j] * b[i]) % MOD; else { dp[i][j] = ((dp[i - 1][j - 1] * a[i]) + (dp[i - 1][j] * b[i])) % MOD; } } } cout << dp[n][c] << "\n"; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t = 1;// cin >> t; while (t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...