Last active
December 15, 2015 21:59
-
-
Save hodduc/5329755 to your computer and use it in GitHub Desktop.
SRM 501 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
double sa, sb; | |
double d[55][55], m[55][55]; | |
class FoxPlayingGame{ | |
public: | |
double theMax(int na, int nb, int pa, int pb) | |
{ | |
int i, j; | |
sa = pa / 1000.0; | |
sb = pb / 1000.0; | |
d[0][0] = m[0][0] = 0; | |
for(i = 1; i <= na; i++){ | |
d[i][0] = d[i-1][0] + sa; | |
m[i][0] = m[i-1][0] + sa; | |
} | |
for(i = 1; i <= na; i++) for(j = 1; j <= nb; j++){ | |
d[i][j] = d[i-1][j] + sa; | |
m[i][j] = m[i-1][j] + sa; | |
if(d[i][j] < d[i][j-1] * sb) d[i][j] = d[i][j-1] * sb; | |
if(m[i][j] > m[i][j-1] * sb) m[i][j] = m[i][j-1] * sb; | |
if(d[i][j] < m[i][j-1] * sb) d[i][j] = m[i][j-1] * sb; | |
if(m[i][j] > d[i][j-1] * sb) m[i][j] = d[i][j-1] * sb; | |
} | |
return d[na][nb]; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment