Created
March 26, 2015 13:40
-
-
Save na-o-ys/e2c87202d2acc7584c97 to your computer and use it in GitHub Desktop.
SRM 654 Div1 Easy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define loop(n, i) for(int i=0;i<n;i++) | |
#define all(v) v.begin(),v.end() | |
using namespace std; | |
class SquareScores | |
{ | |
public: | |
double calcexpectation (vector <int> P, string S) | |
{ | |
vector<double> c_prob(26); | |
loop (P.size(), i) c_prob[i] = 1.0 * P[i] / 100; | |
double ans = 0; | |
loop (26, c) { | |
loop (S.size(), i) { | |
double prob = 1; | |
for (int j = i; j < S.size(); j++) { | |
if (S[j] == '?') { | |
prob *= c_prob[c]; | |
} else if (S[j] - 'a' != c) { | |
prob = 0; | |
} | |
ans += prob; | |
} | |
} | |
} | |
return ans; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment