SRM 370 DIV 2 (500)

Programming/SRM Practice 2009. 5. 26. 17:47
SRM 370 DIV 2 (500)
문제 요약 : 색깔이 중복될 것으로 예상되는 마블의 수를 구하라.

#include <iostream>

#include <vector>

using namespace std;

 

class DrawingMarbles

{

public:

  double sameColor(vector<int> colors, int n);

};

 

double DrawingMarbles::sameColor(vector<int> colors, int n)

{

  int i = 0, j = 0;

  int total = 0;

  double res = 0;

  double sum = 1;

 

  if(colors.size() != 1)

  {

     for(i = 0 ; i < colors.size() ; i++)

         total += colors[i];

     for(i = 0 ; i < colors.size() ; i++)

     {

        for(j = 0 ; j < n ; j++)

          sum *= ((double)colors[i] - (double)j)
                             / ((
double)total - (double)j);

         

        res += sum;

        sum = 1;

     }

  }

  else res = 1.0;

  return res;

}
 

'Programming > SRM Practice' 카테고리의 다른 글

SRM 146 DIV 2 (250)  (0) 2009.05.27
SRM 147 DIV 2 (250)  (0) 2009.05.27
SRM 370 DIV 2 (250)  (0) 2009.05.26
SRM 205 DIV 2 (250)  (0) 2009.05.26
SRM 200 DIV 2 (250)  (0) 2009.05.26
: