Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int mas[40];
  7.  
  8. long long C(int n,int k)
  9. {
  10.     if ((n==k) || (k==0)) {
  11.         return 1;
  12.     }
  13.     if (k==1) {
  14.         return n;
  15.     }
  16.     return C(n-1,k)+C(n-1,k-1);
  17. }
  18.  
  19. int main()
  20. {
  21.     ifstream cin;
  22.     ofstream cout;
  23.     cin.open("comb.in");
  24.     cout.open("comb.out");
  25.     long long n,k,p,c,t,last=0;
  26.     cin >> n >> k >> p;
  27.     for (int i=1; i<=k; i++) {
  28.         c=C(n-i,k-i);
  29.         t=0;
  30.         while (p>=c) {
  31.             t++;
  32.             p-=c;
  33.             c=C(n-t-i,k-i);
  34.         }
  35.         cout << t+1+last << ' ';
  36.         last+=t+1;
  37.     }
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement