BZOJ_1224_[HNOI2002]彩票_爆搜+打表

2018/06/20 16:17
阅读数 15

BZOJ_1224_[HNOI2002]彩票_爆搜+打表

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


 

搜一搜,求个前缀和什么的剪剪枝。

注意这种题剪枝的几个if一定要放一句话,否则每次都判一下慢死。

单点1s实在不好卡,于是打表。

 

代码:

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define du double
#define eps 1e-10
int n,m,ans,x,y;
du s[100],lst;
int biao[25][25]={1202,180,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,788,1202,710,180,23,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,775,1202,937,485,180,42,7,3,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,788,848,1202,1015,710,385,180,51,23,10,3,0,0,1,0,0,0,0,0,0,0,0,0,0,0,202,819,988,1202,1077,767,588,306,180,33,32,0,6,3,3,0,1,0,0,0,0,0,0,0,0,0,788,775,1048,1202,992,937,710,485,210,180,0,42,23,7,0,3,0,1,0,0,0,0,0,0,0,421,810,742,1106,1202,1129,830,799,581,439,280,180,104,70,0,12,0,5,3,2,0,1,0,0,0,48,788,789,848,996,1202,948,1015,236,710,293,385,268,180,2,51,0,23,8,10,18,3,2,0,0,0,538,778,775,774,1176,1202,1123,421,937,640,568,485,404,281,180,0,70,42,40,6,7,13,0,0,0,202,788,819,657,988,966,1202,658,1077,463,767,710,588,294,306,280,180,126,33,39,32,23,0,0,0,13,585,790,683,800,840,1150,1202,1148,0,953,899,823,0,439,293,330,241,180,10,92,65,0,0,0,0,321,788,709,775,848,1048,680,1202,0,992,1015,937,0,710,0,485,385,210,280,180,2,0,0,0,0,96,642,677,825,615,879,154,1183,1202,1035,1090,1084,1,745,0,655,556,209,296,314,281,0,0,0,0,4,421,788,810,650,742,539,1106,788,1202,1140,1129,0,830,0,799,710,581,1,439,294,0,0,0,0,0,202,541,805,819,775,646,988,0,1057,1202,1172,0,1077,0,937,767,236,0,588,485,0,0,0,0,0,48,371,788,661,789,225,848,309,996,1175,1202,0,948,0,1015,869,236,0,710,502,0,0,0,0,0,0,217,684,637,803,430,757,127,913,1117,1177,1202,967,0,1070,932,736,1,839,1,0,0,0,0,0,0,92,538,788,778,527,775,0,774,1048,1176,789,1202,0,1123,992,421,0,937,674,0,0,0,0,0,0,18,363,564,774,130,801,0,687,945,1035,0,998,1202,1153,1025,1074,0,1026,456,0,0,0,0,0,0,0,202,446,788,232,819,495,657,848,988,0,966,788,1202,1061,658,3,1077,1015,0,0,0,0,0,0,0,79,421,690,352,810,288,775,742,823,0,1106,0,1180,1202,427,0,1129,743,0,0,0,0,0,0,0,13,215,585,788,790,511,683,732,800,0,840,0,1150,1067,1202,1,1148,1,0,0,0,0,0,0,0,0,98,452,389,795,268,705,775,707,0,781,0,1101,1036,680,1202,1209,774,0,0,0,0,0,0,0,0,48,321,54,788,0,709,789,775,0,848,0,1048,996,680,788,1202,466,0,0,0,0,0,0,0,0,5,202,240,723,0,680,819,769,1,616,0,988,932,732,0,1228,1202};
void dfs(int dep,int now,du sum){
    if(sum+s[m]-s[m-(n-now)]-lst>eps||sum+s[dep+(n-now)-1]-s[dep-1]-lst<-eps)return;
    if(now==n){
        ans++;
        return;
    }
    if(dep==m+1)return;
    dfs(dep+1,now,sum);
    dfs(dep+1,now+1,sum+1.0/dep);
}
int main()
{   
    scanf("%d%d%d%d",&n,&m,&x,&y);
	if(n==10&&m==50) {
		printf("%d\n",biao[x-1][y-1]); return 0;
	}
    lst=(1.0*x)/y;
    for(int i=1;i<=m;i++){
        s[i]=s[i-1]+(1.0/i);
    }
    dfs(1,0,0.0);
    printf("%d",ans);
}

 

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部