HDU 4865 Peter's Hobby (胡搞)

HDU 4865

Peter’s Hobby

Peter’s Hobby

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 344 Accepted Submission(s): 148

Problem Description

Recently, Peter likes to measure the humidity of leaves. He recorded a leaf humidity every day. There are four types of leaves wetness: Dry , Dryish , Damp and Soggy. As we know, the humidity of leaves is affected by the weather. And there are only three kinds of weather: Sunny, Cloudy and Rainy.For example, under Sunny conditions, the possibility of leaves are dry is 0.6. Give you the possibility list of weather to the humidity of leaves.

The weather today is affected by the weather yesterday. For example, if yesterday is Sunny, the possibility of today cloudy is 0.375. The relationship between weather today and weather yesterday is following by table:

Now,Peter has some recodes of the humidity of leaves in N days.And we know the weather conditons on the first day : the probability of sunny is 0.63,the probability of cloudy is 0.17,the probability of rainny is 0.2.Could you know the weathers of these days most probably like in order?

Input

The first line is T, means the number of cases, then the followings are T cases. for each case: The first line is a integer n(n<=50),means the number of days, and the next n lines, each line is a string shows the humidity of leaves (Dry, Dryish, Damp, Soggy)

Output

For each test case, print the case number on its own line. Then is the most possible weather sequence.( We guarantee that the data has a unique solution)

Sample Input

1 3 Dry Damp Soggy

Sample Output

Case #1: Sunny Cloudy Rainy

Hint

Log is useful.

Author

FZU

Source

2014 Multi-University Training Contest 1

马尔科夫链去转移,记录路径,然后输出结果。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/* ***************

Author :kuangbin

Created Time :2014/7/23 21:58:58

File Name :E:\2014ACM\比赛\2014多校训练\2014多校1\HDU4865.cpp

************************************************ */

#include <stdio.h>

#include <string.h>

#include <iostream>

#include <algorithm>

#include <vector>

#include <queue>

#include <set>

#include <map>

#include <string>

#include <math.h>

#include <stdlib.h>

#include <time.h>

using namespace std;

double dp[100][3];

int pre[100][3];

char str[20];

double a[][4] =

{

{0.6,0.2,0.15,0.05},

{0.25,0.3,0.2,0.25},

{0.05,0.10,0.35,0.50},

};

double b[][3] =

{

{0.5,0.375,0.125},

{0.25,0.125,0.625},

{0.25,0.375,0.375},

};

int get(char str[])

{

if(strcmp(str,"Dry") == 0)return 0;

else if(strcmp(str,"Dryish") == 0)return 1;

else if(strcmp(str,"Damp") == 0)return 2;

else return 3;

}

void out(int i,int t)

{

if(i > 1)out(i-1,pre[i][t]);

if(t == 0)printf("Sunny\n");

else if(t == 1)printf("Cloudy\n");

else printf("Rainy\n");

}

int main()

{

// freopen("1005.in","r",stdin);

//freopen("out.txt","w",stdout);

int T;

int iCase = 0;

int n;

scanf("%d",&T);

while(T--)

{

iCase++;

scanf("%d",&n);

printf("Case #%d:\n",iCase);

dp[0][0] = log(0.63);

dp[0][1] = log(0.17);

dp[0][2] = log(0.2);

for(int i = 1;i <= n;i++)

{

scanf("%s",str);

int id = get(str);

if(i == 1)

{

for(int j = 0;j < 3;j++)

dp[i][j] = dp[i-1][j] + log(a[j][id]);

}

else

{

for(int j = 0;j < 3;j++)

{

dp[i][j] = -100000000.0;

for(int t = 0;t < 3;t++)

{

if(dp[i-1][t] + log(b[t][j])+log(a[j][id]) > dp[i][j])

{

dp[i][j] = dp[i-1][t]+log(b[t][j])+log(a[j][id]);

pre[i][j] = t;

}

}

}

}

}

if(dp[n][0] > dp[n][1] && dp[n][0] > dp[n][2])

out(n,0);

else if(dp[n][1] > dp[n][0] && dp[n][1] > dp[n][2])

out(n,1);

else out(n,2);

}

return 0;

}
------ 本文结束------
  • 本文作者: kuangbin
  • 本文链接: 295.html
  • 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!
0%