好像题目有点问题?且现在决定不吃的宝物以后也不能再吃
好像下次还是可以吃的,就是这样
然后明显是状压dp,注意这道题明显倒推更容易
因为顺推很可能从一个无效状态推到有效状态

 1 var f:array[0..101,0..32768] of double;
 2     v,a:array[0..20] of longint;
 3     i,j,n,m,p,x,k:longint;
 4 
 5 function max(a,b:double):double;
 6   begin
 7     if a>b then exit(a) else exit(b);
 8   end;
 9 
10 begin
11   readln(n,k);
12   m:=1 shl k-1;
13   for i:=1 to k do
14   begin
15     read(v[i]);
16     read(x);
17     while x<>0 do
18     begin
19       a[i]:=a[i]+1 shl (x-1);
20       read(x);
21     end;
22   end;
23   for i:=n downto 1 do
24   begin
25     for j:=0 to m do
26     begin
27       for p:=1 to k do
28         if (a[p] and j)=a[p] then
29           f[i,j]:=f[i,j]+max(f[i+1,j],f[i+1,j or (1 shl (p-1))]+v[p])
30         else f[i,j]:=f[i,j]+f[i+1,j];
31       f[i,j]:=f[i,j]/k;
32     end;
33   end;
34   writeln(f[1,0]:0:6);
35 end.
View Code

 

posted on 2014-12-11 21:18  acphile  阅读(215)  评论(0编辑  收藏  举报