#include #include #include using namespace std; int costo[4]; int Ct=0; int Ct_fix=0; int costo_min; int s_len; int t_len; string s; string t; int get_costo (char a) { switch(a) { case 'A': return costo[0]; break; case 'C': return costo[1]; break; case 'G': return costo[2]; break; case 'T': return costo[3]; break; } } int dec_costo (int pos_t, int pos_s, int Ctemp) { int equal = 1; while (equal && pos_t < t_len && pos_s < s_len) { if (t[pos_t] == s[pos_s]) { Ctemp -= get_costo (t[pos_t]); pos_t++; pos_s++; } else { int possibile = 1; pos_t++; while (possibile && pos_t < t_len && pos_s < s_len) { if (t[pos_t] == s[pos_s]) { Ctemp -= get_costo (t[pos_t]); pos_t++; pos_s++; } else possibile = 0; } equal = 0; } } return Ctemp; } int main () { ifstream fin ("input.txt"); assert (fin); getline (fin,s); getline (fin,t); for (int i = 0; i < 4; i++) fin >> costo[i]; fin.close(); s_len = s.length(); t_len = t.length(); for (int i = 0; i < t_len; i++) Ct += get_costo (t[i]); Ct_fix = costo_min = Ct; for (int i = 0; i < t_len; i++) { Ct = Ct_fix; for (int l = 0; l < s_len; l++) { if (t[i] == s[l]) { Ct -= get_costo (t[i]); Ct = dec_costo (i+1, l+1, Ct); if (Ct <= costo_min) costo_min=Ct; } Ct = Ct_fix; } } ofstream fout ("output.txt"); fout << costo_min << endl; fout.close (); return 0; }