Go: ///
// File:  0546.go
// Author: ymiyamoto
//
// Created on Tue Mar  6 23:19:41 2018
//
package main

import (
	"fmt"
)

var n, k int

func perm(arr []int) [][]int {
	if len(arr) == 1 {
		return [][]int{arr}
	}

	p := perm(arr[1:])
	var ret [][]int
	for _, val := range p {
		for i := 0; i <= len(val); i++ {
			tmp := make([]int, len(val))
			copy(tmp, val)
			tmp = append(tmp, 0)
			copy(tmp[i+1:], tmp[i:])
			tmp[i] = arr[0]
			ret = append(ret, tmp)
		}
	}

	return ret
}

func permutation(n, k int) [][]int {
	ret := [][]int{}

	for i := 0; i < 1<<uint(n); i++ {
		var selects []int
		for j := 0; j < n; j++ {
			if (i>>uint(j))&1 == 1 {
				selects = append(selects, j)
			}
		}
		if len(selects) == k {
			ret = append(ret, perm(selects)...)
		}
	}

	return ret
}

func main() {
	for {
		fmt.Scan(&n, &k)
		if n == 0 && k == 0 {
			break
		}

		cards := make([]string, n)
		for i := 0; i < n; i++ {
			fmt.Scan(&cards[i])
		}

		ret := permutation(len(cards), k)
		nums := map[string]bool{}
		for _, val := range ret {
			var num string
			for i := 0; i < len(val); i++ {
				num += cards[val[i]]
			}
			nums[num] = true
		}

		fmt.Println(len(nums))
	}
}

C++: #include<bits/stdc++.h>

#define int long long int
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repm(a,b,c) for(int a=(b-1);a>=c;a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d",&a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()

using namespace std;

const int INF = 1e18 + 9;
const int Mod = 1e9 + 7;
inline int replac(str s){double ans=0;rep(i,0,s.length()){ans+=(s[i]-'0')*pow(10,s.length()-i-1);}return (int)ans;}
inline string numstr(int m){str s="";while(m>0){char c;int a=m/10;if(a>0)a=m%(a*10);else a=m;c=(char)('0'+a);s+=c;m/=10;}str st="";for(int i=s.size()-1;i>=0;i--){st+=s[i];}return st;}
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
int n,k;
bool used[11]={false};
str s[11];
bool memo[11][11];
set<str> ans;
void f(int num,str st,int nm){
    //if(memo[num][nm])return;
    if(num==k){
        ans.insert(st);
        return;
    }else{
        //memo[num][nm]=true;
        if(nm>=n)return;
        rep(i,0,n){
            if(!used[i]){
                used[i]=true;
                f(num+1,st+s[i],nm+1);
                used[i]=false;
                f(num,st,nm+1);
            }
        }
        return;
    }
}
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(1){
    ans.clear();
    cin >> n;
    cin >> k;
    if(n==0&&k==0)break;
    rep(i,0,n)cin >> s[i];
    //rep(i,0,11)rep(j,0,11)memo[i][j]=false;
    f(0,"",0);
    cout << ans.size() << endl;
    }
    /*for(str k:ans){
        cout << k << endl;
    }*/
    return 0;
}

C++: #include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
using namespace std;

vector<string> num;
int cnt;
void rec(vector<string>& vs,vector<int>& vi,string s,int i,int k){
	if(i==k){
		bool f=true;
		for(int j=0; j<num.size(); ++j){
			if(num[j]==s){
				f=false;
				break;
			}
		}
		if(f) {
			num.push_back(s);
			++cnt;
		}
		return;
	}
	for(int l=0; l<vi.size(); ++l){
		if(vi[l]==0){
			vi[l]=1;
			rec(vs,vi,s+vs[l],i+1,k);
			vi[l]=0;
		}
	}
}
int main(){
	int n,k;
	while(cin>>n>>k&&n!=0&&k!=0){
		cnt=0;
		vector<string> card(n);
		vector<int> ok(n);
		for(int i=0; i<num.size(); ++i){
			num[i]="";
		}
		for(int i=0; i<n; ++i){
			cin >> card[i];
		}
		rec(card,ok,"",0,k);
		/*for(int i=0; i<num.size(); ++i){
			cout << num[i] << "\n";
		}*/
		cout << cnt << "\n";
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int n, k;
    while (cin >> n >> k, n) {
        vector<string> a(n);
        rep(i, n) cin >> a[i];

        set<string> st;
        rep(s, 1 << n) {
            if (__builtin_popcount(s) != k) continue;

            vector<string> b;
            rep(i, n) {
                if ((s >> i) & 1) {
                    b.emplace_back(a[i]);
                }
            }

            sort(all(b));
            do {
                string t = "";
                rep(i, b.size()) {
                    t += b[i];
                }
                if (st.count(t) == 0) {
                    st.insert(t);
                }
            } while (next_permutation(all(b)));
        }

        cout << st.size() << endl;
    }

}

C++: #include <iostream>
#include <vector>
using namespace std;

int n={},k={};
string integer[11]={};
vector<string>num={};
int chousen[11]={};
string complete_integer[10000]={};
string answer={};
int integer_count=0;


void operation(){
    for(int i=1;i<=n;i++){
        if (chousen[i]==0){
            
            chousen[i]=1;
            num.push_back(integer[i]);
        
            if(num.size()==k){
                for(int i=1;i<=k;i++){
                    answer+=num[i-1];
                }
                for(int i=1;i<=integer_count;i++){
                    if(answer==complete_integer[i]){
                        goto none;
                    }
                }
                integer_count+=1;
                complete_integer[integer_count]=answer;

                none:;
                answer={};
            }else{
                operation();
            }
            num.pop_back();
            chousen[i]=0;
        }
        
    }

}