SHARE
TWEET

Untitled

a guest Jan 24th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. int n, k, *vect;
  5.  
  6. unsigned long getResult(int n, int k, int i, int *vect){
  7.    
  8.     if (k > 0 && i == n)
  9.         return 0;
  10.     else if(!k)
  11.         return 1;
  12.  
  13.     int *newVect = new int[n];
  14.     for(int i=0; i<n; i++)
  15.         newVect[i] = vect[i] - 1;
  16.  
  17.     return vect[i]*getResult(n, k-1, i+1, newVect) + getResult(n, k, i+1, vect);
  18. }
  19. int main(){
  20.  
  21.     std::ifstream read("turnuri.in");
  22.     std::ofstream write("turnuri.out");
  23.  
  24.     read>>n>>k;
  25.     vect = new int[n];
  26.  
  27.     for(int i=0; i<n; i++)
  28.         read>>vect[i];
  29.  
  30.     unsigned long result = getResult(n, k, 0, vect);
  31.     std::cout<<result<<std::endl;
  32.     return 0;
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top