BZOJ 1224: [HNOI2002]彩票 搜索

1224: [HNOI2002]彩票

Time Limit: 10 Sec  Memory Limit: 162 MB
Submit: 797  Solved: 304
[Submit][Status][Discuss]

Description

某地发行一套彩票。彩票上写有1到M这M个自然数。彩民可以在这M个数中任意选取N个不同的数打圈。每个彩民只能买一张彩票,不同的彩民的彩票上的选择不同。每次抽奖将抽出两个自然数X和Y。如果某人拿到的彩票上,所选N个自然数的倒数和,恰好等于X/Y,则他将获得一个纪念品。已知抽奖结果X和Y。现在的问题是,必须准备多少纪念品,才能保证支付所有获奖者的奖品。

Input

输入文件有且仅有一行,就是用空格分开的四个整数N,M,X,Y。输出文件有且仅有一行,即所需准备的纪念品数量。 1≤X, Y≤100,1≤N≤10,1≤M≤50。输入数据保证输出结果不超过10^5。

Output

2 4 3 4

Sample Input

1

大爆搜

加上下界剪枝


#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<queue>
#include<map>
#include<set>
#define eps 1e-10
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch<='9'&&ch>='0'){x=10*x+ch-'0';ch=getchar();}
    return x*f;
}
const int N=60;
int n,m,ans;
double aim,x,y,sum[N];
void dfs(int pos,int step,double now)
{
    if(n-pos+1<m-step)return ;
    if(now+sum[pos+m-step-1]-sum[pos-1]-aim<-eps)return ;
    if(now+sum[n]-sum[n+step-m]-aim>eps)return ;
    if(step==m){ans++;return ;}
    dfs(pos+1,step,now);
    dfs(pos+1,step+1,now+1.0/pos);
}
int main()
{
    m=read();n=read();scanf("%lf%lf",&x,&y);aim=x/y;
    for(int i=1;i<=n;i++)sum[i]=sum[i-1]+(1.0/i);
    dfs(1,0,0.0);
    printf("%d\n",ans);
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值