Skip to content

Instantly share code, notes, and snippets.

@na-o-ys
Created March 26, 2015 13:40
Show Gist options
  • Save na-o-ys/e2c87202d2acc7584c97 to your computer and use it in GitHub Desktop.
Save na-o-ys/e2c87202d2acc7584c97 to your computer and use it in GitHub Desktop.
SRM 654 Div1 Easy
#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