hdu 4865 Peter's Hobby

时间:2023-02-08 21:44:34

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.



hdu 4865 Peter's Hobby


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:



hdu 4865 Peter's Hobby


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&amp&semi;&num;39&semi;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&amp&semi;&num;39&semi;s Hobby(概率dp)

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

  3. hdu 4865 Peter&amp&semi;&num;39&semi;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&&num;39&semi;s Hobby(概率、dp、log)

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

  5. HDU 4865 Peter&&num;39&semi;s Hobby --概率DP

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

  6. 2014多校第一场 E 题 &vert;&vert; HDU 4865 Peter&&num;39&semi;s Hobby (DP)

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

  7. HDU 4865 Peter&&num;39&semi;s Hobby&lpar;2014 多校联合第一场 E&rpar;&lpar;概率dp&rpar;

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

  8. HDU 4865 Peter&&num;39&semi;s Hobby

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

  9. Peter&amp&semi;&num;39&semi;s Hobby

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

随机推荐

  1. maven向本地仓库导入jar包(处理官网没有的jar包)

    对于官网没有的jar包,maven向本地仓库导入jar包用如下命令 mvn install:install-file -DgroupId=包名 -DartifactId=项目名 -Dversion=版 ...

  2. LazyLoad&period;js及scrollLoading&period;js

    http://blog.csdn.net/ning109314/article/details/7042829 目前图片延迟加载主要分两大块,一是触发加载(根据滚动条位置加载图片):二是自动预加载(加 ...

  3. HDU 2846 Repository(字典树)

    字典树较为复杂的应用,我们在建立字典树的过程中需要把所有的前缀都加进去,还需要加一个id,判断它原先是属于哪个串的.有人说是AC自动机的简化,但是AC自动机我还没有做过. #include<io ...

  4. http&colon;&sol;&sol;codeforces&period;com&sol;contest&sol;834

    A. The Useless Toy time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  5. &period;net 4&period;5 webform 提取ModelState错误信息

    .net4.5以后,webform也可以使用模型绑定和模型验证. user实体: public class User { [Required] [Display(Name = "用户ID&q ...

  6. 一小时入门PHP

    [版权申明:本文系作者原创,转载请注明出处] 文章出处:[http://blog.csdn.net/sdksdk0/article/details/52332296](http://blog.csdn ...

  7. MySQL 复制 - 性能与扩展性的基石 3:常见问题及解决方案

    主备复制过程中有很大可能会出现各种问题,接下来我们就讨论一些比较普遍的问题,以及当遇到这些问题时,如何解决或者预防问题发生. 1 数据损坏或丢失 问题描述:服务器崩溃.断电.磁盘损坏.内存或网络错误等 ...

  8. Nginx安装及配置详解包括windows环境

    nginx概述 nginx是一款*的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:nginx可以作为一个HTTP服务器进行网站的发布处理,另外 ...

  9. problem:浏览器如何区分html超文本和普通文本

    运营同学问:后端返回的一串元素标签,我想在网页中显示的时候,将标签中的内容渲染出来,不希望直接显示标签. 回答:bootstrap加模版组织的网页,模版渲染的数据只能渲染字符串,不能转化富文本. 运营 ...

  10. python学习之老男孩python全栈第九期&lowbar;day001作业

    1.使用while循环输入 1 2 3 4 5 6     8 9 10 count = 0 while count <= 9: count += 1 if count == 7:continu ...