题解:
暴力+剪纸
判断一下最大行不行,最小行不行
代码:
#include<bits/stdc++.h> const double eps=1e-10; using namespace std; double s[55],q; int n,m,x,y,ans; void dfs(int x,int y,double p) { if (p+s[x+(m-y)-1]-s[x-1]-q<-eps)return; if (p+s[n]-s[n-(m-y)]-q>eps)return; if (y==m){ans++;return;} dfs(x+1,y,p); dfs(x+1,y+1,p+1.0/x); } int main() { scanf("%d%d%d%d",&m,&n,&x,&y); q=(double)x/y; for (int i=1;i<=n;i++) s[i]=s[i-1]+1.0/i; dfs(1,0,0.0); printf("%d",ans); return 0; }