HDU 2200 Eddy's AC难题(组合数学)
2016-01-23 18:04
344 查看
题目链接:HDU 2200
分析:
“从中选择一部分人(或者全部)按照ac的数量分成两组进行比较,他想使第一组中的最小ac数大于第二组中的最大ac数”
如果一共n个数从中选择m个数,共有C(n,m)种方法,选定m个数再往下分可以有m-1种分法,其中n>=m>=2.
所以f(n)=C(n,2)+C(n,3)*2+C(n,4)*3+...+C(n,n)*1
然后写出f(n+1),将其往f(n)化简可得到递推公式:f(n+1)=2*f(n)+2^n-1。打表即可。
代码:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn=100;
long long ans[maxn]={0,0,1};
void init()
{
long long tmp=4;
for(int i=3;i<maxn;i++)
{
ans[i]=2*ans[i-1]+tmp-1;
tmp*=2;
}
}
int main()
{
#ifdef LOCAL
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif
init();
int n;
while(cin>>n)
{
cout<<ans
<<endl;
}
return 0;
}
分析:
“从中选择一部分人(或者全部)按照ac的数量分成两组进行比较,他想使第一组中的最小ac数大于第二组中的最大ac数”
如果一共n个数从中选择m个数,共有C(n,m)种方法,选定m个数再往下分可以有m-1种分法,其中n>=m>=2.
所以f(n)=C(n,2)+C(n,3)*2+C(n,4)*3+...+C(n,n)*1
然后写出f(n+1),将其往f(n)化简可得到递推公式:f(n+1)=2*f(n)+2^n-1。打表即可。
代码:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn=100;
long long ans[maxn]={0,0,1};
void init()
{
long long tmp=4;
for(int i=3;i<maxn;i++)
{
ans[i]=2*ans[i-1]+tmp-1;
tmp*=2;
}
}
int main()
{
#ifdef LOCAL
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif
init();
int n;
while(cin>>n)
{
cout<<ans
<<endl;
}
return 0;
}
相关文章推荐
- Centos 6.5源码安装mysql_5.6.17
- linux下history命令的使用小结
- Android API Level与sdk版本对照表
- 说明
- ubuntu如何实现双屏显示
- 关于WIN7 64位安装ADS2014的总结
- docker 安装
- 大数据应用的几个典型例子
- Python 插件安装
- JS 四舍五入
- UIView中的坐标转换
- iOS block在不同界面的回调传值
- Django后台管理中上传的图片访问不了问题
- hdu 3746 Cyclic Nacklace(KMP求循环节)
- 接口测试-postman+newman+jenkins组合
- csr8670--不能不知道的基本知识,长期记录
- .NET Core 1.0、ASP.NET Core 1.0和EF Core 1.0简介
- Objective-c开发教程--MRC和ARC混编
- IOS开发UI:Quartz2D的使用
- UIImageView添加手势不响应的原因