HNOI2002 彩票

题目链接

题解

暴搜
加个上下界的判断就A了
顺带一题,这题卡精度

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cctype>
#define INF 2000000000
using namespace std;
typedef long long ll;
int n,m,x,y,ans=0;
double sum[55]={0},lim,EPS=1e-11;
int read(){
int f=1,x=0;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
return f*x;
}
void dfs(int at,int lst,double t){
//再取n-at个数
if(at==n){
if(t-lim<EPS&&t-lim>-EPS)ans++;
return ;
}
if(t+sum[m]-sum[m-n+at]-EPS>lim)return ;
//加了最小的还是超过了
for(int i=lst+1;i<=m-n+at+1;i++){
if(t+sum[i+n-at-1]-sum[i-1]+EPS<lim)return ;
//加了最大的还是达不到
dfs(at+1,i,t+1.0/(double)i);
}

}
void init(){
n=read(),m=read(),x=read(),y=read();
for(int i=1;i<=m;i++)
sum[i]=sum[i-1]+1.0/(double)i;
lim=x,lim/=(double)y;
}
void solve(){
for(int i=1;i<=m-n+1;i++)
dfs(1,i,1.0/(double)i);
printf("%d\n",ans);
}
int main(){
init();
solve();
return 0;
}