zoukankan      html  css  js  c++  java
  • a_vj_Judges' response(问题转化:背包壮压+MTSP问题)

    有n-1个参赛选手举手回答问题(每个人的提问时间已确定为(c_i));裁判们都集中在(0,0)位置,每个裁判用于回答问题的时间都不能超过m分钟,问:

    • 求至少需要多少才能回答完所有举手
    • 如果裁判有无数个,问裁判们从出发点出发,回答完问题,然后回到出发点的需要的最少时间

    思路:第一问很好解,第二问不会

    #include<bits/stdc++.h>
    using namespace std;
    const int N=17,inf=0x3f3f3f3f;
    int n,m,ALL,st[1<<N],f[1<<N],c[N];
    vector<int> sta;
    struct node {
        int x,y;
    }A[N];
    int get_cost(int mask) {
        int cost=0;
        for (int i=0; i<n; i++) if (mask&(1<<i)) cost+=c[i];
        return cost<=m ? cost : -1;
    }
    bool init() {
        bool valid=1;
        for (int i=0; i<n; i++) cin>>A[i].x>>A[i].y;
        for (int i=0; i<n; i++) {
            cin>>c[i];
            if (c[i]>m) valid=false;
        }
        ALL=1<<n;
        for (int i=0; i<ALL; i++) if (get_cost(i)!=-1) {
            sta.push_back(i);  
        }
        return valid;
    }
    int solve1() {
        memset(f,inf,sizeof f), f[0]=0;
        for (int j=0; j<ALL; j++) if (f[j]!=inf) 
        for (int s : sta)
            f[j|s]=min(f[j|s], f[j]+1);
        return f[ALL-1];
    }
    int solve2() {
        memset(st,0,sizeof st);
        //to do...
        return 0;
    }
    int main() {
        std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
        while (cin>>n>>m) {
            if (!init()) cout<<-1<<' '<<-1<<'
    ';
            else cout<<solve1()<<' '<<solve2()<<'
    ';
        }
        return 0;
    }
    
  • 相关阅读:
    linux-nginx
    mysql数据库的多实例与主从同步。
    MySQL的命令
    Mysql的管理
    linux之mariadb的安装
    Linux进程基础
    linux网络基础
    解锁HMC8及HMC9的root用户
    RHEL8.0-beta-1.ISO
    RHEL6误安装RHEL7的包导致glibc被升级后系统崩溃处理方法
  • 原文地址:https://www.cnblogs.com/wdt1/p/13947496.html
Copyright © 2011-2022 走看看