【HDU - 2200】Eddy's AC难题(简单组合数学)

版权声明:欢迎学习我的博客,希望ACM的发展越来越好~ https://blog.csdn.net/qq_41289920/article/details/83757716

题干:

Eddy是个ACMer,他不仅喜欢做ACM题,而且对于Ranklist中每个人的ac数量也有一定的研究,他在无聊时经常在纸上把Ranklist上每个人的ac题目的数量摘录下来,然后从中选择一部分人(或者全部)按照ac的数量分成两组进行比较,他想使第一组中的最小ac数大于第二组中的最大ac数,但是这样的情况会有很多,聪明的你知道这样的情况有多少种吗? 

特别说明:为了问题的简化,我们这里假设摘录下的人数为n人,而且每个人ac的数量不会相等,最后结果在64位整数范围内. 

Input

输入包含多组数据,每组包含一个整数n,表示从Ranklist上摘录的总人数。 

Output

对于每个实例,输出符合要求的总的方案数,每个输出占一行。 

Sample Input

2
4

Sample Output

1
17

解题报告:

   因为数字各不相同,我们假设就是1~n。枚举每一个数,计算以他作为右区间的最小值时,产生的贡献。(根据x个元素的集合的子集个数为2^x,非空子集的个数为  (2^x - 1)  )不难得到递推方程、、打表即可。(因为题目说了数据不超longlong,而打表后发现到60的时候已经溢出了,所以只需要打表到60即可。)

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
ll dp[505]; 
ll qpow(ll a,ll k) {
	ll res = 1;
	while(k) {
		if(k&1) res *= a;
		k>>=1;
		a*=a;
	}
	return res;
}
int main()
{
	dp[1] = dp[0] = 0;
	dp[2] = 1;
	for(int i = 3; i<=60; i++) {
		for(int j = 1; j<=i; j++) {
			dp[i] += qpow(2,j-1) * (qpow(2,i-j)-1);
		}
	}
	int n;
	while(~scanf("%d",&n)) {
		printf("%lld\n",dp[n]);
	}
	return 0 ;
 }

猜你喜欢

转载自blog.csdn.net/qq_41289920/article/details/83757716
今日推荐