Weather conditions
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 638 Accepted Submission (s): 257
Problem description If we divide the weather into rainy days, cloudy and sunny 3 kinds, the probability of conversion between a given variety of weather, such as rainy day conversion to rainy days, cloudy and sunny the probability of 0.4,0.3,0.3 respectively. Then, on rainy days, there is rain, The probability of cloudy and sunny Days is 0.4,0.3,0.3. Now give you today's weather conditions, ask you n a day after the occurrence of some weather probability.
Input we assume here that the PIJ represents 3 different weather conditions, and the probability of the change from I weather to J weather.
First, a number T represents the number of groups of data.
Each set of data starts with 9 numbers, p11,p12,p13,......, p32,p33, and the next line is a number m, which indicates the number of questions. Each question has 3 data, i,j,n, expressed over n days from I weather conditions to J weather conditions (1<=i,j<=3 1<=n<=1000).
Output corresponds to the probability of each question being raised (3 decimal places are reserved).
Sample Input10.4 0.3 0.3 0.2 0.5 0.3 0.1 0.3 0.631 1 12 3 11 1 2
Sample Output0.4000.3000.250hint: If the GC submission is unsuccessful, you can change the VC to try
Authorxhd
The puzzle: For each case is the probability of all cases of the previous day multiplied by the probability of a single case today, such as the probability that the rain turns to rain from the first to the third day, it is necessary to use the probability of the day before (rain, sunshine, yin) to multiply the probability of today's rain to the same, The next day was pushed by the first day
VIS[J][K][I]+=MAP[L][K]*VIS[J][L][I-1];
#include <stdio.h> #include <string.h> #include <algorithm> #define MAX 1100#include<math.h># Define DD doubledd Map[4][4];DD vis[4][4][max];using namespace Std;int main () {int n,m,j,i,t,k,l;int a,b,c;scanf ("%d", & Amp;t), while (t--) {memset (vis,0,sizeof (VIS)), for (i=1;i<=3;i++) for (j=1;j<=3;j++) { scanf ("%lf ", &map[i][j]); VIS[I][J][1]=MAP[I][J]; } for (i=2;i<1010;i++)//days {for (j=1;j<=3;j++)//by I weather {for (k=1;k<=3;k++)//go to K weather {for (l=1;l<=3;l++)// This loop is used to cycle the weather change {vis[j][k][i]+=map[l][k]*vis[j][l][i-1];//The probability of J-change K of the day I //map the current day each weather goes to K probability//vis[j][l][i-1] Probability of each weather for the previous day}}}}scanf ("%d", &n), while (n--) {scanf ("%d%d%d", &a,&b,&c);p rintf ("%.3lf\n", Vis[a][b][c] );}} return 0;}
HDU 1437 weather conditions "probability DP"