#include #include #include #include #include #include #include #include #include #include using namespace std; #define FOREACH(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it) template inline int size(const T&c) { return c.size(); } int RIGHT_LIMIT, WRONG_LIMIT; string s; int cache[2501][51][51]; int f(int poz, int rr, int ww) { int &res = cache[poz][rr][ww]; if(res!=-1) return res; if(poz==size(s)) { res=0; return res; } res = 0; if(rr>0) { res = max(res, (s[poz]=='G') + f(poz+1, rr-1, WRONG_LIMIT)); } if(ww>0) { res = max(res, (s[poz]=='B') + f(poz+1, RIGHT_LIMIT, ww-1)); } return res; } struct Horoscope { // MAIN int maxGoodDays(vector predictions, int R, int W) { RIGHT_LIMIT = R; WRONG_LIMIT = W; s = ""; FOREACH(it,predictions) s += *it; memset(cache,-1,sizeof(cache)); return f(0,RIGHT_LIMIT,WRONG_LIMIT); } }; // Powered by FileEdit // Powered by TomekAI // Powered by TZTester 1.01 [25-Feb-2003] // Powered by CodeProcessor