• HNOI2002]*


    嘟嘟嘟

    遇到这种无从下手且数据范围特别小的题,直接一波爆搜加剪枝就行了。

    爆搜就是选到的数是严格从大到小的,这样才能保证复杂度是C(n, m)的,然后枚举每一个数是选了还是没选。

    剪枝有这么几点。

    1.如果当前值比x / y大,返回(显然~)。

    2.如果当前值加上最小值仍比x / y大,返回。

    3.如果当前值加上最大值仍比x / y小,返回。

    至于加上最大值最小值,可以下预处理倒数和的前缀和,然后最小值就是sum[m - (n - step), m],最大值就是sum[num + n - step - 1, num],其中num表示枚举到序列中的第num个数,step表示选了step个数。

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cmath>
     4 #include<algorithm>
     5 #include<cstring>
     6 #include<cstdlib>
     7 #include<cctype>
     8 #include<vector>
     9 #include<stack>
    10 #include<queue>
    11 using namespace std;
    12 #define enter puts("") 
    13 #define space putchar(' ')
    14 #define Mem(a) memset(a, 0, sizeof(a))
    15 typedef long long ll;
    16 typedef double db;
    17 const int INF = 0x3f3f3f3f;
    18 const db eps = 1e-10;
    19 const int maxn = 55;
    20 inline ll read()
    21 {
    22     ll ans = 0;
    23     char ch = getchar(), last = ' ';
    24     while(!isdigit(ch)) {last = ch; ch = getchar();}
    25     while(isdigit(ch)) {ans = ans * 10 + ch - '0'; ch = getchar();}
    26     if(last == '-') ans = -ans;
    27     return ans;
    28 }
    29 inline void write(ll x)
    30 {
    31     if(x < 0) x = -x, putchar('-');
    32     if(x >= 10) write(x / 10);
    33     putchar(x % 10 + '0');
    34 }
    35 
    36 int n, m, x, y;
    37 db ans, Sum[maxn];
    38 ll tot = 0;
    39 
    40 void dfs(int num, int step, db sum)
    41 {
    42     db Min = sum + Sum[m] - Sum[m - (n - step)];
    43     db Max = sum + Sum[num + n - step - 1] - Sum[num - 1];
    44     if(Min > ans + eps || Max < ans - eps) return;
    45     if(step == n) {tot++; return;}
    46     if(num == m + 1) return;
    47     dfs(num + 1, step, sum);
    48     dfs(num + 1, step + 1, sum + 1.0 / (db)num);
    49 }
    50 
    51 
    52 int main()
    53 {
    54     n = read(); m = read(); x = read(); y = read();
    55     ans = (db)x / (db)y;
    56     for(int i = 1; i <= m; ++i) Sum[i] = Sum[i - 1] + 1.00 / (db)i;
    57     dfs(1, 0, 0.0);
    58     write(tot); enter;
    59     return 0;
    60 }
    View Code
  • 相关阅读:
    【软件构造】Lab1基本流程指导及重难点分析
    【软件构造】关于java中List和Set数据结构不同实现方式和不同遍历方式时间效率的探讨与分析
    程序人生-Hello’s P2P
    WinterCamp2017吃饭睡觉记
    bzoj 3144 [Hnoi2013]切糕
    bzoj 1565 [NOI2009]植物大战僵尸
    bzoj 1061 [Noi2008]志愿者招募
    序列
    Philosopher
    时机成熟之时
  • 原文地址:https://www.cnblogs.com/mrclr/p/9566966.html
Copyright © 2020-2023  润新知