fork download
  1. #include <vector>
  2. #include <list>
  3. #include <map>
  4. #include <set>
  5. #include <deque>
  6. #include <stack>
  7. #include <bitset>
  8. #include <algorithm>
  9. #include <functional>
  10. #include <numeric>
  11. #include <utility>
  12. #include <sstream>
  13. #include <iostream>
  14. #include <iomanip>
  15. #include <cstdio>
  16. #include <cmath>
  17. #include <cstdlib>
  18. #include <ctime>
  19. #include <cstring>
  20. using namespace std;
  21.  
  22. template <class T> inline void checkmin(T &x,T t){if (t<x) x=t;}
  23. template <class T> inline void checkmax(T &x,T t){if (t>x) x=t;}
  24.  
  25. class RedIsGood {
  26. public:
  27. double getProfit(int, int);
  28. };
  29. const int N=5005;
  30. double F[2][N];
  31.  
  32. double RedIsGood::getProfit(int R, int B) {
  33. memset(F,0,sizeof(F));
  34. for (int i=0;i<=R;i++){
  35. int p=i&1;
  36. for (int j=0;j<=B;j++)
  37. if (i+j){
  38. if (j==0) F[p][j]=F[p^1][j]+1;
  39. else if (i) checkmax( F[p][j] , (F[p^1][j]+1)*(1.0*i/(i+j)) + (F[p][j-1]-1)*(1.0*j/(i+j)) );
  40. }
  41. memset(F[p^1],0,sizeof(F[p^1]));
  42. }
  43. return F[R&1][B];
  44. }
  45.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty