Peter's Hobby

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 283    Accepted Submission(s): 128

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
 

题目:给的信息就是每天树叶的状态和今天天气有一定的关系。明天的天气和今天的天气也有一定的关系,眼下给出n天的树叶状态以及第一天三种天气的概率。来求出这n概率最大的天气序列。

题解:比赛的时候也想到了这道题的计算方法,可是认为不是非常合理,当然看了赛后的题解依旧认为不合理,可是还是依照题解做了一下。我认为不合理之处是题目中给出的是依据天气看树叶状态的概率,而题目中给出的是树叶的状态来推天气状况,这就让大家想到 要求条件概率,而不是简单得相乘-----个人见解,假设认为说的不正确。求指正。

一条天气链的概率的求法s[a1]*wh[a1][b1]*ww[a1][a2]*wh[a2][b2]*.......*ww[an-1][an]*wh[an][bn];由于乘机太小。所以转化成log来求和,取最大的那条就能够了。

由于每天仅仅有三种天气状态。使用dp[i][j]来记录从第一天到第i天的概率和(第i天为第j种天气),过程中使用path[i][j]记录前一天的天气情况。

最后找出最后一天概率和最大的天气,依据path向前推,找出全部的天气就可以。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std; double wh[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.50};
double ww[3][3]={0.5,0.375,0.125,
0.25,0.125,0.625,
0.25,0.375,0.375}; int main()
{
int t,cas=1,n,h[55];
char s[10];
cin>>t;
while(t--)
{
cin>>n;
for(int i=0;i<n;i++)
{
scanf("%s",s);
if(strcmp(s,"Dry")==0) h[i]=0;
else if(strcmp(s,"Dryish")==0) h[i]=1;
else if(strcmp(s,"Damp")==0) h[i]=2;
else h[i]=3;
} double dp[55][3],path[55][3],print[55]; dp[0][0]=log(0.63*wh[0][h[0]]);
dp[0][1]=log(0.17*wh[1][h[0]]);
dp[0][2]=log(0.20*wh[2][h[0]]); for(int i=1;i<n;i++)
{
for(int j=0;j<3;j++)
{
double max=-1e7;
int v=-1;
for(int k=0;k<3;k++)
if(max<dp[i-1][k]+log(wh[j][h[i]]*ww[k][j]))
{
v=k;
max=dp[i-1][k]+log(wh[j][h[i]]*ww[k][j]);
}
dp[i][j]=max;
path[i][j]=v;
}
}
int k=0;
if(dp[n-1][1]>dp[n-1][k]) k=1;
if(dp[n-1][2]>dp[n-1][k]) k=2;
print[n-1]=k;
for(int i=n-1;i>=1;i--)
{
print[i-1]=path[i][k];
k=print[i-1];
}
cout<<"Case #"<<cas++<<":"<<endl;
for(int i=0;i<n;i++)
{
if(print[i]==0) printf("Sunny\n");
else if(print[i]==1) printf("Cloudy\n");
else printf("Rainy\n");
}
}
return 0;
}

hdu 4865 Peter&#39;s Hobby的更多相关文章

  1. hdu 4865 Peter&#39;s Hobby(2014 多校联合第一场 E)

    Peter's Hobby Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

  2. hdu 4865 Peter&#39;s Hobby(概率dp)

    http://acm.hdu.edu.cn/showproblem.php? pid=4865 大致题意:有三种天气和四种叶子状态.给出两个表,各自是每种天气下叶子呈现状态的概率和今天天气对明天天气的 ...

  3. hdu 4865 Peter&#39;s Hobby (隐马尔可夫模型 dp)

    Peter's Hobby Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

  4. HDU 4865 Peter's Hobby(概率、dp、log)

    给出2个影响矩阵,一个是当天天气对湿度的影响,一个是前一天天气对当天天气的影响. 即在晴天(阴天.雨天)发生Dry(Dryish.Damp.Soggy)的概率,以及前一天晴天(阴天.雨天)而今天发生晴 ...

  5. HDU 4865 Peter's Hobby --概率DP

    题意:第i天的天气会一定概率地影响第i+1天的天气,也会一定概率地影响这一天的湿度.概率在表中给出.给出n天的湿度,推测概率最大的这n天的天气. 分析:这是引自机器学习中隐马尔科夫模型的入门模型,其实 ...

  6. 2014多校第一场 E 题 || HDU 4865 Peter's Hobby (DP)

    题目链接 题意 : 给你两个表格,第一个表格是三种天气下出现四种湿度的可能性.第二个表格是,昨天出现的三种天气下,今天出现三种天气的可能性.然后给你这几天的湿度,告诉你第一天出现三种天气的可能性,让你 ...

  7. HDU 4865 Peter's Hobby(2014 多校联合第一场 E)(概率dp)

    题意:已知昨天天气与今天天气状况的概率关系(wePro),和今天天气状态和叶子湿度的概率关系(lePro)第一天为sunny 概率为 0.63,cloudy 概率 0.17,rainny 概率 0.2 ...

  8. HDU 4865 Peter's Hobby

    $dp$. 这题的本质和求一个有向无环图的最长路径长度的路径是一样的. $dp[i][j]$表示到第$i$天,湿度为$a[i]$,是第$j$种天气的最大概率.记录一下最大概率是$i-1$天哪一种天气推 ...

  9. Peter&#39;s Hobby

    主题链接 题意: 题意比較麻烦.. .n天,给出每天的叶子的一种状态(Dry , Dryish , Damp and Soggy),最有可能出现的天气序列(Sunny, Cloudy and Rain ...

随机推荐

  1. Linux Timer定时器【转】

    转自:https://www.jianshu.com/p/66b3c75cae81 timerfd为Linux为用户程序提供的定时器接口,该接口基于文件描述符,通过文件描述符的可读事件进行超时通知,且 ...

  2. jquery easyui:tab自动加载第一个tab内容

    $('#resourceTabs').tabs('unselect', 0);$('#resourceTabs').tabs('select', 0);

  3. 乐视max2 在开发中无法打印某些logcat 解决方案

    乐视屏蔽了打印log.d等类型logcat.解决方案:拨号键盘 *#*#76937#*#* 出现页面后选最下面那个选项就有了.

  4. IntelliJ IDEA 中安装junit插件

    1.在Intellij IDEA 中安装了 Junit,TestNG插件,首先检查一下intellij IDEA 是否在安装时默认安装了这两个插件,检查方法 打开 settings -->Plu ...

  5. jQuery预览图

  6. java8中ConcurrentHashMap

    HashMap的线程不安全主要体现在resize时的死循环及使用迭代器时的fast-fail上. Fast-fail: fail-fast 机制是java集合(Collection)中的一种错误机制. ...

  7. 在k8s集群中,利用prometheus的jmx_exporter进行tomcat的JVM性能监控,并用grafana作前端展示

    查找了很多文档,没有完全达到我要求的, 于是,作了一定的调整,成现在这样. 操作步骤如下: 一,准备好两个文件. jmx_prometheus_javaagent-0.3.1.jar jmx_expo ...

  8. IE下css bug集合-翻译自haslayout.net

    概述IE浏览器以不支持大量的css 属性出名,同时也因其支持的css属性中存在大量bug. 本页列举了IE下的一些问题,实例样本和一些我们已知的解决方法. 尽管我已经尽力按照它们本来的性质对它们进行分 ...

  9. transition动画

    http://rainleaves.com/demo/transition/transition.html

  10. Jupyter notebook安装与使用

    Jupyter Notebook(此前被称为 IPython notebook)是一个交互式笔记本,支持运行 40 多种编程语言. 安装 安装python 3 pip安装 pip3 install - ...