import java.math.*;
import java.util.Scanner;
class Main {
static BigInteger stir(int x,int y){
if(y>x)
return BigInteger.ZERO;
if(y==1||x==y)
return BigInteger.ONE;
x--;y--;
if(y>x/2)
y=x-y;
BigInteger sum=BigInteger.ONE;
int Y=y;
while(Y-->0)
sum=sum.multiply(BigInteger.valueOf(x--));
while(y>1)
sum=sum.divide(BigInteger.valueOf(y--));
return sum;
}
public static void main(String[] args){
Scanner in=new Scanner(System.in);
int t=in.nextInt();
while(t-->0){
int n,k;
n=in.nextInt();
k=in.nextInt();
if(k==0){
System.out.println(1);
continue;
}
int K=k,sum=0;
while(K-->0)
sum+=in.nextInt();
{
int l=n-sum;
BigInteger p=stir(l,k-1);
p=p.add(stir(l,k).multiply(BigInteger.valueOf(2)));
p=p.add(stir(l,k+1));
System.out.println(p);
}
}
}
}
import java.util.Scanner;
class Main {
static BigInteger stir(int x,int y){
if(y>x)
return BigInteger.ZERO;
if(y==1||x==y)
return BigInteger.ONE;
x--;y--;
if(y>x/2)
y=x-y;
BigInteger sum=BigInteger.ONE;
int Y=y;
while(Y-->0)
sum=sum.multiply(BigInteger.valueOf(x--));
while(y>1)
sum=sum.divide(BigInteger.valueOf(y--));
return sum;
}
public static void main(String[] args){
Scanner in=new Scanner(System.in);
int t=in.nextInt();
while(t-->0){
int n,k;
n=in.nextInt();
k=in.nextInt();
if(k==0){
System.out.println(1);
continue;
}
int K=k,sum=0;
while(K-->0)
sum+=in.nextInt();
{
int l=n-sum;
BigInteger p=stir(l,k-1);
p=p.add(stir(l,k).multiply(BigInteger.valueOf(2)));
p=p.add(stir(l,k+1));
System.out.println(p);
}
}
}
}
Comments
Post a Comment