In the morning, I couldn't take any tests. I was taught to be a human, and my mentality exploded ......
Description:
You are playing your favorite video game and have just entered a reward level. In this reward, the system will randomly throw K treasures, and each time you can choose to eat or not to eat (you must make a choice before throwing out the next treasure, and now you decide not to eat any more ).
There are N types of treasures. Each time the system throws these N types of treasures, the probability is the same and independent of each other. That is to say, even if the previous K-1 system throws the treasure 1 (this situation is possible, although the probability is very small), the probability of each Treasure thrown for the K is still 1/N.
If you get the I-th type of treasures, you will get PI points, but not every kind of treasures can be obtained at will. The first kind of treasures has a set of prerequisite treasures Si. Only when all the treasures in Si have been eaten at least once can we eat the No. 1 treasures (if the system throws a treasure that cannot be eaten at present, it is equivalent to a loss of white space ). Note that pi can be a negative number, but if it is the premise of many high-score treasures, it will gain greater long-term benefits if it loses short-term benefits and eats this negative score.
Suppose you adopt the optimal strategy. On average, how much score can you get from the reward level?
1 <= k <= 100, 1 <= n <= 15, and the score is an integer in [-106,106.
Train of Thought Analysis:
N is very small, and it is obvious that the state is DP. The binary state sta indicates the state of N treasures, 0 indicates that they have not been eaten, and 1 indicates that they have been eaten. Launched the DP status. f [I] [sta] indicates that the current status is in the I round. The status of the first I round is STA, and the maximum expected value can be obtained through the optimal strategy.
During the transfer, enumeration J indicates the I-th round. The J-treasure is dropped.
However, transfer is hard to write, or cannot be written at all. Why? Next we will discuss it with you.
I am a Renren-I cannot judge which of the I-th treasures is better to eat or not to eat (because after pushing it, I + 1] [sta | 1 <( j-1)], if this parameter is not set, it is [I + 1] [sta]. The two are inconsistent)
Write for others-unable to determine which State it was transferred from (because J, which is probably from round I enumeration, is the only J-type treasure, it may also be the only one, so it is difficult to tell which status should be transferred from)
So what should we do? -- If you can't do anything, please wait!
Status: F [I] [sta] indicates the K (total number of rounds) from the I turn, get the best solution, and now in the I-1 round, the greatest value you can expect when you eat the treasure is Sta.
During transfer, enumerating a j indicates that the treasure that appears in the I-1 wheel is J (the following pre array is the prerequisite item 01 that can be selected by the treasure J (the binary I-bit 0/1 represents the I item is/not the prerequisite item of item j) number of States in decimal format. W indicates the value)
Condition: STA | pre [J] = pre [J] transfer: F [I] [sta] = f [I] [sta] + max (F [I + 1, sta], F [I + 1, Sta | 1 <(J-1)] + W [J])
Condition: STA | pre [J] <> pre [J] transfer: f [I] [sta] = f [I] [sta] + F [I + 1] [sta]
Where f [I + 1] [sta | 1 <(J-1)] indicates the I-1 round to eat treasures J, f [I + 1] [sta] indicates that the I-1 wheel does not eat treasure J.
Code implementation:
var f:array[0..101,0..50000]of double; pre,w:array[0..15]of longint; x,k,n,i,sta,j:longint;function max(a,b:double):double;begin if a>b then exit(a) else exit(b);end;begin read(k,n); for i:=1 to n do begin read(w[i],x); while x<>0 do begin pre[i]:=pre[i] or 1<<(x-1); read(x); end; end; for i:=k downto 1 do for sta:=0 to 1<<n-1 do for j:=1 to n do if sta and pre[j]=pre[j] then f[i,sta]:=f[i,sta]+max(f[i+1,sta]/n,(f[i+1,sta or 1<<(j-1)]+w[j])/n) else f[i,sta]:=f[i,sta]+f[i+1,sta]/n; writeln(f[1,0]:0:6);end.
Scoi 2008 [rewards]