POJ - 1080 枚举

Posted The Azure Arbitrator

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了POJ - 1080 枚举相关的知识,希望对你有一定的参考价值。

要求max{F/P},先枚举下界lowf,再贪心求符合约束条件的n个最小价值和
记录F的离散值和去重可以大幅度常数优化
(本来想着用DP做的)
(辣鸡POJ连auto都Complie Error)

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<iterator>
using namespace std;
const int maxn = 1e5+11;
typedef pair<int,int> P;
vector<P> vec[maxn];
vector<int> F;
int n,m,x,y;
int main(){
    int T; scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        memset(vec,0,sizeof vec); F.clear();
        for(int i = 1; i <= n; i++){
            scanf("%d",&m);
            for(int j = 1; j <= m; j++){
                scanf("%d%d",&x,&y);
                vec[i].push_back(P(x,y));
                F.push_back(x);
            }
        }
        sort(F.begin(),F.end());
        vector<int>::iterator it = unique(F.begin(),F.end());
        F.erase(it,F.end());
        double ans=-1;
        long long tmp=0;
        for(int k = 0; k < F.size(); k++){//enum the lb of F
            int lowf=F[k];
            tmp=0;
            bool flag=0;
            for(int i = 1; i <= n; i++){
                int mn=0x7fffffff;
                for(int tt = 0; tt < vec[i].size(); tt++){
                    P t=vec[i][tt];
                    if(t.first>=lowf){
                        mn=min(mn,t.second);
                    }
                }
                if(mn==0x7fffffff)flag=1;
                tmp+=mn;
            }
            if(flag==1) continue;
            ans=max(ans,(double)lowf/tmp);
        }
        printf("%.3lf\n",ans);
    }
    return 0;
}

以上是关于POJ - 1080 枚举的主要内容,如果未能解决你的问题,请参考以下文章

LCS poj1080

poj 1080 (LCS变形)

poj1080 - Human Gene Functions (dp)

POJ 1080 Human Gene Functions(DP)

poj 1080 Human Gene Functions(lcs,较难)

Human Gene Functions POJ 1080 最长公共子序列变形