CSU 1725 Garrosh hell growl vs Ghost thief Rafam (DP)

Source: Internet
Author: User

Test instructions: X attacks, Garrosh have y blood, z three blood slave master, and then the slave owner every one of the non-fatal damage will be regenerated a Slave Lord, on the field up to 7 slave owners, ask you the last to kill Garrosh the probability of how much?

Problem: DP recursion, the key is how to design the state, the beginning did not think well, was the gold medal ye Hu a sentence with crooked to the shape of pressure, in fact, the state does not need any four-way pressure, in fact, very simple

dp[number of attacks [garrosh of remaining blood] [three blood slave master number] [two blood count] [one blood count], because the data range is particularly small, so how to make time is very rich ah

And then the final answer is to add all 0 blood states.

Recursion is the classification considering the field there are 7 strange and less than 7 strange state, and then transfer the good, alas, I actually did not think of such a simple problem, DP or too slag, but also too easy to listen to other people's ideas.


#include <map> #include <set> #include <stack> #include <queue> #include <cmath> #include <string> #include <vector> #include <cstdio> #include <cctype> #include <cstring># Include <sstream> #include <cstdlib> #include <iostream> #include <algorithm> #pragma comment ( linker, "/stack:102400000,102400000") using namespace std; #define MAX 200005#define MAXN 500005#defin E maxnode 105#define sigma_size 2#define lson l,m,rt<<1#define Rson m+1,r,rt<& Lt;1|1#define LRT rt<<1#define RRT rt<<1|1#define Middle int m= (r+l) >>1 #define LL Long long#define ull unsigned long long#define mem (x,v) memset (x,v,sizeof (x)) #d Efine lowbit (x) (x&-x) #define PII pair<int,int> #define BITS (a) __builtin_popcount (a) #d       Efine Mk Make_pair#define Limit  10000//const int prime = 999983;const int INF = 0x3f3f3f3f;const LL inff = 0x3f3f;const double pi = ACOs ( -1.0); const double inf = 1e18;const double eps = 1e-9;const LL mod = 1e9+7;const ull mx = 1e9+7;/********      /inline void RI (int &x) {char C;      while (C=getchar ()) < ' 0 ' | | c> ' 9 ');      x=c-' 0 '; while ((C=getchar ()) >= ' 0 ' && c<= ' 9 ') x= (x<<3) + (x<<1) +c-' 0 ';} /*****************************************************/double Dp[21][21][10][10][10];int Main () {//freopen ("    Test.txt "," R ", stdin);    int t;    cin>>t;        while (t--) {int x, y, Z;        cin>>x>>y>>z;        MEM (dp,0);        Dp[x][y][z][0][0]=1;        Double ans=0;                    for (int i=x-1;i>=0;i--) {for (int. j=1;j<=y;j++) {for (int k=0;k<=7;k++) {    for (int kk=0;kk<=7;kk++) {for (int kkk=0;kkk<=7;kkk++) {                        if (k+kk+kkk>7) break;                            dp[i][j-1][k][kk][kkk]+=1.0/(k+kk+kkk+1) *DP[I+1][J][K][KK][KKK];                                 if (k+kk+kkk==7) {if (k) dp[i][j][k-1][kk+1][kkk]+=k*1.0/(k+kk+kkk+1) *DP[I+1][J][K][KK][KKK];                                if (KK) dp[i][j][k][kk-1][kkk+1]+=kk*1.0/(k+kk+kkk+1) *DP[I+1][J][K][KK][KKK];                            if (KKK) dp[i][j][k][kk][kkk-1]+=kkk*1.0/(k+kk+kkk+1) *DP[I+1][J][K][KK][KKK]; } else{if (k) dp[i][j][k][kk+1][kkk]+=k*1.0/(k+kk+kkk+1) *dp[i+                                1][J][K][KK][KKK];                                if (KK) dp[i][j][k+1][kk-1][kkk+1]+=kk*1.0/(k+kk+kkk+1) *DP[I+1][J][K][KK][KKK];                            if (KKK) dp[i][j][k][kk][kkk-1]+=kkk*1.0/(k+kk+kkk+1) *DP[I+1][J][K][KK][KKK];     }                        }                    }                }            }   } for (int i=0;i<x;i++) {for (int. k=0;k<=7;k++) {for (int kk=0;kk<=7;kk++) {                for (int kkk=0;kkk<=7;kkk++) ANS+=DP[I][0][K][KK][KKK];    }}} printf ("%.6f\n", ans); } return 0;}



CSU 1725 Garrosh hell growl vs Ghost thief Rafam (DP)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.