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.

概率dp  time :0ms
#include"iostream"
#include"cstdio"
#include"map"
#include"cstring"
#include"string"
#include"algorithm"
#include"vector"
using namespace std;
const int ms=;
double p1[][]= {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 p2[][]= {0.5,0.375,0.125,0.25,0.125,0.625,0.25,0.375,0.375};
double dp[ms][];
int pre[ms][];
map<int,string> m1;
map<string,int> m2;
string str;
void init()
{
m2.insert(make_pair("Dry",));
m2.insert(make_pair("Dryish",));
m2.insert(make_pair("Damp",));
m2.insert(make_pair("Soggy",));
m1.insert(make_pair(,"Sunny"));
m1.insert(make_pair(,"Cloudy"));
m1.insert(make_pair(,"Rainy"));
}
int main()
{
int ncase,T=;
scanf("%d",&ncase);
init();
while(ncase--)
{
printf("Case #%d:\n",++T);
int n,i,j,k;
scanf("%d",&n);
cin>>str;
for(i=;i<=n;i++)
for(j=;j<;j++)
dp[i][j]=;
int lab=m2[str];
memset(pre,,sizeof(pre));
dp[][]=0.63*p1[][lab];
dp[][]=0.17*p1[][lab];
dp[][]=0.2*p1[][lab];
for(i=;i<=n;i++)
{
cin>>str;
lab=m2[str];
for(j=;j<;j++)
for(k=;k<;k++)
{
double pp=dp[i-][k]*p2[k][j]*p1[j][lab];
if(pp>dp[i][j])
{
dp[i][j]=pp;
pre[i][j]=k;
}
}
}
vector<int> ans;
double mi=;
int po;
for(i=;i<;i++)
if(dp[n][i]>mi)
{
mi=dp[n][i];
po=i;
}
ans.push_back(po);
int now=n;
while(now!=)
{
po=pre[now][po];
ans.push_back(po);
now--;
}
for(i=n-;i>=;i--)
{
//printf("%s\n",m1[ans[i]]);
cout<<m1[ans[i]]<<endl;
}
}
return ;
}

Peter's Hobby的更多相关文章

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

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

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

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

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

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

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

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

  5. HDU 4865 Peter's Hobby

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

  6. hdu 4865 Peter&#39;s Hobby

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

  7. 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 ...

  8. 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 ...

  9. hdu 4865 dp

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

随机推荐

  1. bzoj 1458 士兵占领(最大流)

    [题意] n行m列,第i行必须放L[i],第j列必须放C[j],有障碍格,求满足条件至少需要放多少. [思路] 至少放多少等价于最多不放多少. 对行列分别建XY点,则连边(S,Xi,a)(Yi,T,b ...

  2. C# 与 VC Dll 传输信息

    考虑: 使用string类型传送: 在VC Dll中解析字符: 使用 string 类型将解析的类型传送到C#程序中: 建立VC解析的函数,提高代码可重用性

  3. 应用数据存储到sdcard上一定要规范,android4.4.2有新规范

    如果你的android设备有内部存储空间,即通常所说的机身存储(这就是指主要外部存储),那么你从外部插入SD卡就是一个二级外部存储设备. 最新的Android 4.4系统中,外置存储卡(SD卡)被称为 ...

  4. Nginx的代理和反向代理

    什么是代理? 代理是为网络用户代理了来访问网络的,比如Google agent代理FQ. 什么是反向代理? 以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服 ...

  5. Linux的运行级别和chkconfig用法

    Linux的运行级别和chkconfig用法        一.Linux的运行级别 在装MySQL的时候,才知道了Linux的运行级别这么一回事.汗…自己太水了…下面总结一下: 什么是运行级别呢?简 ...

  6. 340. Longest Substring with At Most K Distinct Characters

    最后更新 二刷 08-Jan-2017 和76.159很像.. 2 pointers.. 通过判断是否每一次是有效读取来增减accumulator,从而判断当前是否符合规定,再来更新maxLength ...

  7. 使用PUT方法上传文件无法工作原因分析

    现象 在Spring Framework中,使用HTTP的PUT方法上传文件时,在服务器端发现Multipart参数为空. 原因 Spring中的StandardServletMultipartRes ...

  8. nexus建立maven仓库私服及Snapshots、release的版本管理

    环境搭建   1.linux安装maven   wget http://mirrors.cnnic.cn/apache/maven/maven-3/3.0.5/binaries/apache-mave ...

  9. leetcode第一刷_Count and Say

    水题. 描写叙述的还挺麻烦的,实际上就是纸老虎,用两个string,一个存上一轮的结果,一个用来更新出这一轮的结果,每次扫描上一轮,统计一个字符出现的次数,然后把这个次数和字符增加到这一轮的字符串中就 ...

  10. CDOJ 483 Data Structure Problem DFS

    Data Structure Problem Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/proble ...