How can this question be so ambiguous ...
DescriptionLittle Q classmate now indulge in the legend of the Furnace Stone can't extricate themselves. He found a card called Kosuien very unfair. If you don't play the legend of the stone, don't worry, little QThe reunion tells you all the relevant details. The legend of the Furnace Stone is such a game, each player has a 30-point amount of blood hero, and can use cardssummon up to 7 followers to help the player attack opponents, each with their own amount of blood and damage. Little Q classmates have a lot of game failures arebecause the opponent used the Kosuien card, he wanted to find some way to resist kosuien. He went to get help. Professional Furnace stone legend the player's name is white, really whitetell him to use the slave Master card. If you don't understand what I'm talking about, don't worry, Little Q homecoming tells you what he wants you to do .. Now the small Q reunion give Kosuien attack is K, that Kosuien will attack K times, each time from the opponent field heroes and followers randomly selectedSelect one and generate 1 damage to it. Now the other side has a gram sole, you have some slave owners as companions, each Slave Lord's blood volume is given. If Kosuien attacks one of your slaves, the slave owner's blood will be reduced by 1, and will die if the blood volume is less than or equal to 0 .not to die after the attack, and the number of your followers has not reached 7, the slave Lord will summon a new slave owner with 3 points of blood as your entourage.If Kosuien attacks your hero, your hero will record 1 damage. You should have noticed that whenever kosuien an attack, youThe attendant on the field may have changed a lot. Small Q classmate For you assume the attack of Kosuien, you have 1 points on the field, 2 points, 3 points of blood volumeThe number of slave owners, can you figure out how much your hero's total damage is expected to be? Input contains multi-board games. The first line contains an integer T (t<100) that represents the game's number of innings. Each game occupies only one row, contains four non-negative integers k, A, B and C, indicating that Kosuien's attack is K, you have a 1-point amount of slave master, B 2-point blood of the Slave master, C 3-point blood volume of the slave owner. Guaranteed K is a positive number less than 50, a+b+c not more than 7. Output
For each game, output a number that represents the expected total damage and retains two decimal places.
Problem analysis
Expect DP to be really too immature ... Violence can be played.
1#include <cstdio>2 3 intt,k,a,b,c;4 Doubleans;5 6 voidDfsintDoneintN1,intN2,intN3,intBldDoubleSTA)7 {8 if(done==k| |! Bldreturn;9 if(N1) DFS (done+1, n1-1, N2, N3, BLD, STA*n1/(n1+n2+n3+1.0));Ten if(n2) { One if(N1+n2+n3 <7) ADFS (done+1, n1+1, n2-1, n3+1, BLD, STA*n2/(n1+n2+n3+1.0)); - ElseDFS (done+1, n1+1, n2-1, N3, BLD, STA*n2/(n1+n2+n3+1.0)); - } the if(n3) { - if(N1+n2+n3 <7) -DFS (done+1, N1, n2+1, N3, BLD, STA*n3/(n1+n2+n3+1.0)); - ElseDFS (done+1, N1, n2+1, n3-1, BLD, STA*n3/(n1+n2+n3+1.0)); + } -Ans + = sta/(n1+n2+n3+1.0); +DFS (done+1, N1, N2, N3, Bld, sta/(n1+n2+n3+1.0)); A } at intMain () - { -Freopen ("cthun.in","R", stdin); -Freopen ("Cthun.out","W", stdout); -scanf"%d",&T); - while(t--) in { -Ans =0; toscanf"%d%d%d%d",&k,&a,&b,&c); +Dfs0, A, B, C, -,1.0); -printf"%.2lf\n", ans); the } * return 0; $}
This is violence. The red part means: For n slave owners, one of them is not the same, so the probability of moving to this state is multiplied by N.
The expectation is that the DP is usually inverted: $f [t][i][j][k]$ indicates the initial state is $ (t,i,j,k) $, and the final gain is expected.) The advantage of this is that all initial states can be preprocessed, and the transfer time will be more convenient, without the probability of recording transfer.
So this is a point that needs to be applied flexibly.
1#include <cstdio>2#include <cctype>3 4 intt,k,a,b,c;5 Doublef[ -][ -][ -][ -];6 7 intRead ()8 {9 intnum =0;Ten BOOLFL =0; One CharCH =GetChar (); A for(;!isdigit (CH); ch=GetChar ()) - if(ch=='-') FL =1; - for(; isdigit (CH); ch=GetChar ()) thenum = (num<<1) + (num<<3) +ch- -; - if(fl) num =-num; - returnnum; - } + intMain () - { +Freopen ("cthun.in","R", stdin); AFreopen ("Cthun.out","W", stdout); at for(intt=1; t<= -; t++) - for(intI=0; i<=7; i++) - for(intj=0; i+j<=7; J + +) - for(intk=0; i+j+k<=7; k++) - { - Doublesum = i+j+k+1.0; inF[t][i][j][k] + = (f[t-1][i][j][k]+1)/sum; -F[t][i][j][k] + = f[t-1][i-1][j][k]*i/sum; to if(I+j+k <7) +F[t][i][j][k] + = f[t-1][i+1][j-1][k+1]*j/Sum, -F[t][i][j][k] + = f[t-1][i][j+1][k]*k/sum; the Else *F[t][i][j][k] + = f[t-1][i+1][j-1][k]*j/Sum, $F[t][i][j][k] + = f[t-1][i][j+1][k-1]*k/sum;Panax Notoginseng } -T =read (); the while(t--) printf ("%.2lf\n", F[read ()][read ()][read ()][read ()]); + return 0; A}
END
"Expected DP" bzoj4832: [Lydsy1704 month] boycott Kosuien