HDOJ 4865 Peter's Hobby,hdoj4865

來源:互聯網
上載者:User

HDOJ 4865 Peter's Hobby,hdoj4865


隱馬爾可夫模型介紹見這裡:點擊開啟連結

Peter's HobbyTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 362    Accepted Submission(s): 160


Problem DescriptionRecently, 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? 
InputThe 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) 
OutputFor 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
13DryDampSoggy
 
Sample Output
Case #1:SunnyCloudyRainyHintLog is useful. 
 
AuthorFZU 
Source2014 Multi-University Training Contest 1 


#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;int n;double lea[3][4]={{0.6,0.2,0.15,0.05},{0.25,0.3,0.2,0.25},{0.05,0.1,0.35,0.5}};double wea[3][3]={{0.5,0.375,0.125},{0.25,0.125,0.625},{0.25,0.375,0.375}};int ord[100],pre[100][100];double dp[100][100];void output(int day,int weather){if(day<0) return;output(day-1,pre[day][weather]);//cout<<"day: "<<day<<" weather: "<<weather<<endl;if(weather==0)puts("Sunny");else if(weather==1)puts("Cloudy");else if(weather==2)puts("Rainy");}int main(){int T_T,cas=1;scanf("%d",&T_T);for(int i=0;i<3;i++){for(int j=0;j<4;j++){lea[i][j]=log(lea[i][j]);if(j<3)wea[i][j]=log(wea[i][j]);}}while(T_T--) {scanf("%d",&n);memset(dp,0,sizeof(dp));memset(pre,0,sizeof(pre));char leaf[20];for(int i=0;i<n;i++){scanf("%s",leaf);if(strcmp(leaf,"Dry")==0)ord[i]=0;else if(strcmp(leaf,"Dryish")==0)ord[i]=1;else if(strcmp(leaf,"Damp")==0)ord[i]=2;else ord[i]=3;}dp[0][0]=log(0.63)+lea[0][ord[0]];dp[0][1]=log(0.17)+lea[1][ord[0]];dp[0][2]=log(0.2)+lea[2][ord[0]];for(int i=1;i<n;i++){for(int j=0;j<3;j++){double mx=-1000000000;int mr=-1;for(int k=0;k<3;k++){double temp=dp[i-1][k]+wea[k][j]+lea[j][ord[i]];if(temp>mx){mx=temp; mr=k;}}dp[i][j]=mx; pre[i][j]=mr;}}double mx=-1000000000;int mr=-1;for(int i=0;i<3;i++){if(mx<dp[n-1][i]){mr=i;mx=dp[n-1][i];}}printf("Case #%d:\n",cas++);output(n-1,mr);}return 0;}






聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.