#include
#include
#include
using namespace std;
double dp[55][55][650];
int a[55],b[55];
int check(char ch)
{
if(ch=='A') return 1;
if(ch=='X') return 10;
if(ch=='J') return 11;
if(ch=='Q') return 12;
if(ch=='K') return 13;
return ch-'0';
}
int main()
{
int n,k,t;
scanf("%d",&t);
while(t--)
{
char str[3];
double C=1;
double f1[650],f2[650];
int sum1=0,sum2=0;
scanf("%d%d",&n,&k);
for(int i=1;i<=k;i++)
C=C*(n-i+1)/i;
for(int i=1;i<=n;i++)
{
scanf("%s",str);
a[i]=check(str[0]);
sum1+=a[i];
}
for(int i=1;i<=n;i++)
{
scanf("%s",str);
b[i]=check(str[0]);
sum2+=b[i];
}
memset(dp,0,sizeof(dp));
for(int i=0;i<=n;i++)
dp[i][0][0]=1;
for(int i=1;i<=n;i++)
for(int j=1;j<=i&&j<=k;j++)
for(int d=1;d<=sum1;d++)
{
if(d>=a[i])
dp[i][j][d]=dp[i-1][j][d]+dp[i-1][j-1][d-a[i]];
else
dp[i][j][d]=dp[i-1][j][d];
}
for(int i=1;i<=sum1;i++)
f1[i]=1.0*dp[n][k][i]/C;
memset(dp,0,sizeof(dp));
for(int i=0;i<=n;i++)
dp[i][0][0]=1;
for(int i=1;i<=n;i++)
for(int j=1;j<=i&&j<=k;j++)
for(int d=1;d<=sum2;d++)
{
if(d>=b[i])
dp[i][j][d]=dp[i-1][j][d]+dp[i-1][j-1][d-b[i]];
else
dp[i][j][d]=dp[i-1][j][d];
}
f2[0]=0.0;
for(int i=1;i<=sum1;i++)
{
f2[i]=1.0*dp[n][k][i]/C;
f2[i]+=f2[i-1];
}
double cnt=0;
for(int i=1;i<=sum1;i++)
cnt+=(double)f1[i]*f2[i-1];
printf("%.6lf\n",1.0*cnt);
}
return 0;
}
/**********************************************************************
Problem: 1206
User: 3901140225
Language: C++
Result: AC
Time:524 ms
Memory:17384 kb
**********************************************************************/
#include
#include
#define MOD 1000000007
#define maxn 25
long long C[25][25];
long long ret[maxn][maxn];
long long init[maxn][maxn];
long long buf[maxn][maxn];
void matrixMul(long long a[][maxn] , long long b[][maxn] , long long n,long long mod)
{
long long i,j,k;
for(i=0;ifor(j=0;j0;
}
}
for(i=0;ifor(k=0;kif(a[i][k]==0)
continue;
for(j=0;jif(b[k][j]==0)
continue;
buf[i][j]+=a[i][k]*b[k][j];
if (buf[i][j]>=mod||buf[i][j]<=-mod)
{
buf[i][j]%=mod;
}
}
}
}
for(i=0;ifor(j=0;jvoid matrixMul(long long n,long long m,long long mod)
{
long long i,j;
for(i=0;ifor(j=0;jfor(;m;m>>=1)
{
if(m&1)
{
matrixMul(ret,init,n,mod);
}
matrixMul(init,init,n,mod);
}
}
void initc()
{
C[0][0]=C[1][0]=C[1][1]=1;
for(int i=2;i<=20;i++)
{
for(int j=0;j<=i&&j<=20;j++)
{
if(j==0)
C[i][j]=1;
else
C[i][j]=(C[i-1][j]+C[i-1][j-1])%MOD;
}
}
}
int main()
{
initc();
int t,n,k,i,j;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&k);
if(n==1)
{
printf("1\n");
continue;
}
else if(n==2)
{
printf("2\n");
continue;
}
memset(init,0,sizeof(init));
for(i=0;i<=k;i++)
{
for(j=0;j<=k-i;j++)
{
init[j][i]=C[k-i][j];
}
}
for(i=0;i<=k;i++)
{
init[i][k+1]=C[k][i];
}
init[k+1][k+1]=1;
matrixMul(k+2,n-2,MOD);
long long ans=0;
for(i=0;i<=k;i++)
{
ans=(ans+ret[i][k+1])%MOD;
}
ans=(ans+2*ret[k+1][k+1])%MOD;
printf("%lld\n",ans);
}
return 0;
}
/**********************************************************************
Problem: 1208
User: 3901140225
Language: C++
Result: AC
Time:168 ms
Memory:1140 kb
**********************************************************************/
import java.util.*;
import java.math.*;
public class Main {
public static void main(String [] args)
{
Scanner input = new Scanner(System.in);
while(input.hasNext())
{
String str = input.next();
BigInteger num = new BigInteger(str);
int len = str.length();
int len1 = (len+1)/2;
BigInteger factor = BigInteger.valueOf(20);
BigInteger factor1 = BigInteger.valueOf(10);
BigInteger div = BigInteger.valueOf(0);
BigInteger ans = BigInteger.valueOf(0);
BigInteger left = BigInteger.valueOf(0);
int t = 0 , index = 0;
if(len%2 == 1){
t = str.charAt(0)-'0';
index+=1;
}else{
t = str.charAt(0)-'0';
t = t*10 + str.charAt(1)-'0';
index+=2;
}
int m = (int)Math.sqrt(t*1.0+0.1);
ans = BigInteger.valueOf(m);
div = BigInteger.valueOf(m).multiply(factor);
left = BigInteger.valueOf(t-m*m);
// System.out.println(ans);
BigInteger tmp = BigInteger.valueOf(0);
for(int i=1 ; i
int val = str.charAt(index)-'0';
val = val*10+str.charAt(index+1)-'0';
left = left.add(BigInteger.valueOf(val));
// System.out.println("div: "+i+" "+div+" "+left);
int j=9;
for(; j>=0 ; j--){
tmp = div.add(BigInteger.valueOf(j));
if(left.compareTo(tmp.multiply(BigInteger.valueOf(j)))>=0) break;
}
left = left.subtract(tmp.multiply(BigInteger.valueOf(j)));
ans = ans.multiply(factor1).add(BigInteger.valueOf(j));
div = ans.multiply(factor);
}
System.out.println(ans);
}
}
}