ZOJ 4535 ZOJ Monthly, October 2011 H

本文介绍了如何通过编程计算集合中不相交子集的总数,并提供了代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

How Many Sets I

Time Limit: 2 Seconds Memory Limit: 65536 KB

Give a set S, |S| = n, then how many ordered set group (S1, S2, ..., Sk) satisfies S1 ∩ S2 ∩ ... ∩ Sk = ∅. (Si is a subset of S, (1 <= i <= k))

Input

The input contains multiple cases, each case have 2 integers in one line represent n and k(1 <= k <= n <= 231-1), proceed to the end of the file.

Output

Output the total number mod 1000000007.

Sample Input
1 1
2 2
Sample Output
1
9

整套比赛最简单的一个。
可以直接写一个暴力程序,然后找规律。
规律很显然的~

我的代码:
#include<stdio.h>
#include<iostream>

using namespace std;

typedef long long ll;

ll mod=1000000007;

ll power(ll p,ll n,ll m)
{
	ll sq=1;
	while(n>0)
	{
		if(n%2==1)
			sq=(sq%m)*(p%m)%m;
		p=(p%m)*(p%m)%m;
		n=n/2;
	}
	return sq%m;
}

int main()
{
	ll n,k,ans;
	while(cin>>n>>k)
	{
		ans=power(2,k,mod)-1;
		ans=power(ans,n,mod);
		cout<<ans<<endl;
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值