Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int comb(int arriba,int abajo){
- if (abajo==0)
- return 1;
- if (abajo==1)
- return arriba;
- int aux=1;
- for (int i=abajo+1;i<=arriba;i++)
- aux=aux*i;
- for (int i=1;i<=(arriba-abajo);i++)
- aux=aux/i;
- return aux;
- }
- int main() {
- int n,k;
- vector<int>v;
- while(cin>>n>>k){
- int aux;
- for(int i=0;i<k;i++){
- cin>>aux;v.push_back(aux);
- }
- sort(v.begin(),v.end());
- int resp=1,arriba=n;
- for(int i=k-1;i>=0,v[i]>0,arriba>0;i--){
- resp=resp*comb(arriba,v[i]);
- arriba-=v[i];
- }
- cout<<resp<<endl;
- v.clear();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment