zoukankan      html  css  js  c++  java
  • 杂务

    P1113 杂务

    这道题我爆0啦,有点dp的小味道,显然,一个工程的完成时间由最慢的人决定(可以同时进行),m[i]代表完成杂物i所需的最少时间,m[i]=max(m[i],m[j]+v[i]),j是需要在i之前完成的杂物,最慢的也要完成,所以要取最大。虽然题目中说准备工作只可能在杂务1..k-1中,但这并不代表着在完成n之前,需要把1~n-1都要完成,所以要扫一遍。

    #include<bits/stdc++.h>
    using namespace std;
    queue<int>q;
    int n;
    int in[100010];
    bool b[100010];
    int v[100010];
    int m[100010];
    int ans;
    struct node
    {
        int n;
        node *next;
    }*e[100010];
    int main()
    {
        cin>>n;
        node *p;
        int x;
        for(int i=1;i<=n;i++)
        {
            p=new node();
            int t;
            cin>>p->n;
            t=p->n;
            cin>>v[p->n];
            cin>>x;
            while(x!=0)
            {
            in[p->n]+=1;
            if(e[x]==NULL)
            e[x]=p;
            else
            {
                p->next=e[x]->next;
                e[x]->next=p;
            }
            cin>>x;
            p=new node();
            p->n=t;
            }
        }
        for(int i=1;i<=n;i++)
        if(in[i]==0)
        {
        q.push(i);
        m[i]=v[i];    
        }
        while(!q.empty())
        {
            node *p;
            p=e[q.front()];
          while(p!=NULL)
         {
            in[p->n]-=1;
            if(in[p->n]==0)
            {
                q.push(p->n);
            }
            m[p->n]=max(m[p->n],m[q.front()]+v[p->n]);
            p=p->next;
         }  
         q.pop();
        }
        for(int i=1;i<=n;i++)
        ans=max(ans,m[i]);
        cout<<m[n];
        return 0;
    }
  • 相关阅读:
    函数的调用惯例
    docker 强制删除镜像
    docker 安装 tomcat8
    阿里云 maven仓库地址配置
    ubuntu 18.04 安装搜狗输入法
    centos 监控进程,并自动重启
    intellj idea show "run dashboard" panel
    Centos7 服务器启动jar包
    maven centos7 环境变量
    linux关于IP,端口,防火墙相关命令
  • 原文地址:https://www.cnblogs.com/war1111/p/7418108.html
Copyright © 2011-2022 走看看