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. java类加载与初始化

    第一段: class A{ public A(){ this.list(); } public void list(){ System.out.println("in a list..&qu ...

  2. Spark RDD概念学习系列之Spark的数据存储(十二)

    Spark数据存储的核心是弹性分布式数据集(RDD). RDD可以被抽象地理解为一个大的数组(Array),但是这个数组是分布在集群上的. 逻辑上RDD的每个分区叫一个Partition. 在Spar ...

  3. work_6

    这次的作业是阅读C++11的新特性并提出问题,作为一个大部分代码都是用C++的基本语法并没有特别关注C++一代又一代新特性的学生来说,首先我阅读了一些关于新特性的文章.为了更快的理解,我首先选择了阅读 ...

  4. 条件编译#ifdef的妙用详解_透彻

    这几个宏是为了进行条件编译.一般情况下,源程序中所有的行都参加编译.但是有时希望对其中一部分内容只在满足一定条件才进行编译,也就是对一部 分内容指定编译的条件,这就是“条件编译”.有时,希望当满足某条 ...

  5. 我所理解的设计模式(C++实现)——备忘录模式(Memento Pattern)

    概述: 我们玩单机游戏的时候总会遇到老婆大人的各位事情,一会去买瓶醋了,一会去打个酱油了,会耽误我们玩游戏的进程,但是此时我们能有“保存游戏”这个宝贝,我们的主基地不会在我们打酱油的时候被对手拆掉. ...

  6. Java中字符串相等与大小比较

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html 内部邀请码:C8E245J (不写邀请码,没有现金送) 国 ...

  7. Spring声明式事务的配置~~~

    /*2011年8月28日 10:03:30 by Rush  */ 环境配置 项目使用SSH架构,现在要添加Spring事务管理功能,针对当前环境,只需要添加Spring 2.0 AOP类库即可.添加 ...

  8. SqlServer教程:经典SQL语句集锦

    SQL分类: DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE) DML—数据操纵语言(SELECT,DELETE,UPDATE,INSERT) DCL—数据控制语言(GRAN ...

  9. 关于STM32的ST官方的库的一点看法

    标题确实很别扭,因为我现在用这个库也很别扭. 在不久之前,一直有个讨论的话题:STM32开发是用库还是用寄存器? 很多人的结论是不需要讨论! 但是,今天我想说下我的看法. 首先,我还是一个菜鸟,对库对 ...

  10. Codeforces Round #329 (Div. 2) D. Happy Tree Party 树链剖分

    D. Happy Tree Party Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/593/p ...