【瞎搞】 HDU 5098 Smart Software Installer

点击打开链接

题意:

安装包A 安装 前需要 安装 安装包B

安装某个包的时候需要重启,求安装完所有所需最小重启次数


图是DAG

求一个权值最大的链,所以搜一遍

输入居然是这样的= = 

A:X Y Z

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#include<queue>
#include <string>
#include <sstream>
#include <map>
#include <vector>
map<string,int>mp;
vector<int>g[2020];
char ss[5231];
int mark[2044];
int dfs(int u)
{
    int flag=0,Max=0;
    if(mark[u]==1) flag=1,Max=1;
    for(int i=0;i<g[u].size();i++)
    {
        int v=g[u][i];
        Max=max(Max,dfs(v)+flag);
    }
    return Max;
}
int main()
{
    int t;
    cin>>t;
    getchar();
    int T=1;
    gets(ss);
    while(t--)
    {
        mp.clear();
        memset(mark,0,sizeof(mark));
        int idx=0;
        for(int i=0;i<=2011;++i)
            g[i].clear();
        while(gets(ss))
        {
            if(strlen(ss)==0)
                break;
            stringstream sss;
            sss<<ss;
            string a="", b="";
            sss>>a;
            int x,y,flag=0;
            if(a[a.size()-2]=='*')
                a=a.substr(0,a.size()-2),flag=1;
            else a=a.substr(0,a.size()-1);
         //   cout<<a<<endl;
            if(mp.find(a)==mp.end())
                mp[a]=++idx;
            x=mp[a];
            if(flag) mark[x]=1;
            while(sss>>b)
            {
              //  cout<<b<<endl;
                if(mp.find(b)==mp.end())
                    mp[b]=++idx;
                y=mp[b];
                g[y].push_back(x);
               // cout<<y<<x<<endl;
            }

        }
        int ans=0;
        for(int i=1;i<idx;i++)
            ans=max(ans,dfs(i));
        printf("Case %d: %d\n",T++,ans);
    }
    return 0;
}

/*
100

e*:
c*:
a*:
a*: b
b: c
a: d
d: e
*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值