karlangadas

Polynomial Coefficients

Dec 9th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5. int comb(int arriba,int abajo){
  6.     if (abajo==0)
  7.         return 1;
  8.     if (abajo==1)
  9.         return arriba;
  10.        
  11.     int aux=1;
  12.     for (int i=abajo+1;i<=arriba;i++)
  13.         aux=aux*i;
  14.     for (int i=1;i<=(arriba-abajo);i++)
  15.         aux=aux/i;
  16.     return aux;
  17. }
  18. int main() {
  19.     int n,k;
  20.     vector<int>v;
  21.     while(cin>>n>>k){
  22.         int aux;
  23.         for(int i=0;i<k;i++){
  24.             cin>>aux;v.push_back(aux);
  25.         }
  26.         sort(v.begin(),v.end());
  27.         int resp=1,arriba=n;
  28.         for(int i=k-1;i>=0,v[i]>0,arriba>0;i--){
  29.             resp=resp*comb(arriba,v[i]);
  30.             arriba-=v[i];
  31.         }
  32.         cout<<resp<<endl;
  33.         v.clear();
  34.     }
  35.    
  36.    
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment