#include #include // #include "../Kody/simple-console-debug/debug.h" using namespace std; int n,k,p; string init_state; vectorV(1000); int best_letter_val; //get best partial solution long long R(int start, int jump, int alpha, int current_n){ // deb::Indent ind; // cerr << ind.head << "R(start=" << start << " jump=" << jump << " alpha=" << alpha << " current_n=" << current_n << endl; //edge case if(alpha==0) return init_state[start]=='?' ? best_letter_val : V[init_state[start]]; //check if possible all equal char the_one = '?'; for(int i=start;;){ if(init_state[i]!='?'){ if(the_one=='?') the_one = init_state[i]; else if(the_one!=init_state[i]){ the_one = '!'; break; } } i=(i+jump)%n; if(i==start) break; } // cerr << ind << "the_one=" << the_one << endl; long long sol1 = 0; if(the_one!='!'){ long long val = (the_one=='?') ? best_letter_val : V[the_one]; sol1 = val*(alpha+1)*current_n; } //check without this assumption long long sol2 = 0; for(int i=0;i