-
algospot - numb3rsAlgorithm/알고스팟 2020. 2. 7. 16:101234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162//numb3rs#include <iostream>#include <vector>using namespace std;int N, D, P;vector<vector<int>> adj;vector<vector<double>> cache;vector<int> Size;void init(){cin >> N >> D >> P;adj = vector<vector<int>>(N, vector<int>(N));cache = vector<vector<double>>(N, vector<double>(D + 1, -1));Size = vector<int>(N, 0);for (int i = 0; i < N; ++i)for (int j = 0; j < N; ++j){cin >> adj[i][j];if (adj[i][j])++Size[i];}}double dp(int idx, int day){if (!day)return idx == P ? 1.0 : 0.0;double &ret = cache[idx][day];if (ret != -1)return ret;ret = 0;for (int i = 0; i < N; ++i)if (adj[i][idx])ret += dp(i, day - 1) / (double)Size[i];return ret;}int main(){ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);int C;cin >> C;cout << fixed;cout.precision(8);for (int tn = 0; tn < C; ++tn){init();int n; cin >> n;int idx;for(int i = 0; i<n; ++i){cin >> idx;cout << dp(idx, D) << " ";}cout << "\n";}}
cs https://www.algospot.com/judge/problem/read/NUMB3RS
algospot.com :: NUMB3RS
두니발 박사의 탈옥 문제 정보 문제 위험한 살인마 두니발 박사가 감옥에서 탈출했습니다. 수배지를 붙이고 군경이 24시간 그를 추적하고 있지만 용의주도한 두니발 박사는 쉽사리 잡히지 않았습니다. d일이 지난 후에야 경찰은 프로그래밍의 천재인 찰리 교수)를 찾아왔습니다. 찰리 교수는 두니발 박사가 감옥에 남겨둔 노트를 분석해 다음과 같은 가설을 세웠습니다. 두니발 박사는 검문을 피해 산길로만 이동한다. 두니발 박사는 교도소를 탈출한 당일, 교도소와 인접한 마
www.algospot.com
NUMB3RS
C(idx, day) : day번째 날에 idx마을에 있을 확률
<NUMB3RS 점화식> 'Algorithm > 알고스팟' 카테고리의 다른 글
algospot - packing (0) 2020.02.10 algospot - snail (0) 2020.02.08 algospot - poly (0) 2020.02.07 algospot - asymtiling (0) 2020.02.03 algospot - tripathcnt (0) 2020.02.03