悲伤地回忆,当初写了一个作死的算法爆零了
为什么不好好写暴力呢……
显然设w[i]表示彻底干掉这个怪物的代价
注意发现这里的转移具有后效性,但是干掉每个怪物的最优值是一定的
我们用spfa来转移,详见那篇spfa的论文

 1 type node=record
 2        po,next:longint;
 3      end;
 4 
 5 var e,ee:array[0..1000010] of node;
 6     p,pp,d:array[0..200010] of longint;
 7     q:array[0..10000010] of longint;
 8     w:array[0..200010] of int64;
 9     v:array[0..200010] of boolean;
10     len,t,i,n,s,j,x:longint;
11 
12 procedure add(x,y:longint);
13   begin
14     e[len].po:=y;
15     e[len].next:=p[x];
16     p[x]:=len;
17   end;
18 
19 procedure addp(x,y:longint);
20   begin
21     ee[len].po:=y;
22     ee[len].next:=pp[x];
23     pp[x]:=len;
24   end;
25 
26 procedure spfa;
27   var x,y,f,r,i:longint;
28       s:int64;
29   begin
30     f:=1;
31     r:=n;
32     for i:=1 to n do
33     begin
34       q[i]:=i;
35       v[i]:=true;
36     end;
37     while f<=r do
38     begin
39       x:=q[f];
40       v[x]:=false;
41       i:=pp[x];
42       s:=d[x];
43       while i<>0 do  //转移
44       begin
45         s:=s+w[ee[i].po];
46         i:=ee[i].next;
47         if s>=w[x] then break;
48       end;
49       if s<w[x] then
50       begin
51         w[x]:=s;
52         i:=p[x];
53         while i<>0 do  //能用普通攻击变出这个怪物的怪物的最小代价可能发生变化
54         begin
55           y:=e[i].po;
56           if not v[y] then
57           begin
58             inc(r);
59             q[r]:=y;
60             v[y]:=true;
61           end;
62           i:=e[i].next;
63         end;
64       end;
65       inc(f);
66     end;
67   end;
68 
69 begin
70   readln(n);
71   for i:=1 to n do
72   begin
73     read(d[i],w[i],s);
74     for j:=1 to s do
75     begin
76       inc(len);
77       read(x);
78       addp(i,x);
79       add(x,i);
80     end;
81     readln;
82   end;
83   spfa;
84   writeln(w[1]);
85 end.
86 
87  
View Code

 

posted on 2015-01-31 23:25  acphile  阅读(130)  评论(0编辑  收藏  举报