10.24 test3 T2

题干

在这里插入图片描述
在这里插入图片描述

solution

在这里插入图片描述

对于位运算来说,每一位是独立的,所以单独考虑每一位,然后用乘法原理乘起来
dp[i][j]表示前i行中j列有1的方案数

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int p=1e9+7;
int read()
{
	char ch=' ';
	int f=1;int x=0;
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
	    x=x*10+ch-'0';ch=getchar();
	}
	return x*f;
}
int c[60][60];
int exp[60];
void pre_work()
{
	for(int i=0;i<=50;i++)
	{
		for(int j=0;j<=i;j++)
		{
			if(i==j||j==0) c[i][j]=1;
			else c[i][j]=(c[i-1][j-1]+c[i-1][j])%p;
		}
	}
	exp[0]=1;
	for(int i=1;i<=50;i++)
	{
		exp[i]=exp[i-1]*2%p;
	}
}
int n,m,k;
int f[60][60];
void dp()
{
	for(int i=0;i<=m;i++)
	{
		f[1][i]=c[m][i];
	}
	for(int i=1;i<n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			f[i+1][j]+=f[i][j]*(exp[j]-1)%p;
			f[i+1][j]%=p;
			for(int k=j+1;k<=m;k++)
			{
				f[i+1][k]+=f[i][j]*c[m-j][k-j]%p*exp[j]%p;
			}
		}
	}
}
int mul(int x,int y)
{
	int ret=1;
	while(y)
	{
		if(y&1)
		{
			ret=ret*x%p;
		}
		x=x*x%p;
		y=y>>1;
	}
	return ret;
}
int main()
{
	int t;
	t=read();
	pre_work();
	while(t--)
	{
		n=read();m=read();k=read();
		memset(f,0,sizeof(f));
		int i,j;
		dp();
		cout<<mul(f[n][m],k)<<endl;
	}
	return 0;
}