Peter's Hobby
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?
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)
line. Then is the most possible weather sequence.( We guarantee that the data
has a unique solution)
Log is useful.
#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的更多相关文章
- HDU 4865 Peter's Hobby(概率、dp、log)
给出2个影响矩阵,一个是当天天气对湿度的影响,一个是前一天天气对当天天气的影响. 即在晴天(阴天.雨天)发生Dry(Dryish.Damp.Soggy)的概率,以及前一天晴天(阴天.雨天)而今天发生晴 ...
- HDU 4865 Peter's Hobby --概率DP
题意:第i天的天气会一定概率地影响第i+1天的天气,也会一定概率地影响这一天的湿度.概率在表中给出.给出n天的湿度,推测概率最大的这n天的天气. 分析:这是引自机器学习中隐马尔科夫模型的入门模型,其实 ...
- 2014多校第一场 E 题 || HDU 4865 Peter's Hobby (DP)
题目链接 题意 : 给你两个表格,第一个表格是三种天气下出现四种湿度的可能性.第二个表格是,昨天出现的三种天气下,今天出现三种天气的可能性.然后给你这几天的湿度,告诉你第一天出现三种天气的可能性,让你 ...
- HDU 4865 Peter's Hobby(2014 多校联合第一场 E)(概率dp)
题意:已知昨天天气与今天天气状况的概率关系(wePro),和今天天气状态和叶子湿度的概率关系(lePro)第一天为sunny 概率为 0.63,cloudy 概率 0.17,rainny 概率 0.2 ...
- HDU 4865 Peter's Hobby
$dp$. 这题的本质和求一个有向无环图的最长路径长度的路径是一样的. $dp[i][j]$表示到第$i$天,湿度为$a[i]$,是第$j$种天气的最大概率.记录一下最大概率是$i-1$天哪一种天气推 ...
- hdu 4865 Peter's Hobby
Peter's Hobby Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- hdu 4865 Peter's Hobby (隐马尔可夫模型 dp)
Peter's Hobby Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- hdu 4865 Peter's Hobby(2014 多校联合第一场 E)
Peter's Hobby Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- hdu 4865 dp
Peter's Hobby Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
随机推荐
- 暴雪hash算法
你有一个非常大的字符串数组A,现在又有一个字符串B,需要你去检测B是否存在于A中.最简单粗暴的方法是遍历整个A,但是这个方法投入到实际应用时的运行速度是难以接受的.在没有与其他所有字符串比较前怎么知道 ...
- Tasks Queues and Cron Jobs(任务队列和时钟守护作业)
一个网络应用必须迅速响应网络请求,一般要小于1s,最好是几十微秒,以便为坐在浏览器前面的用户提供一个流畅的体验.这就给不了应用太多的时间来处理工作.有时会是有更多的工作要做而不是有时间来做它.< ...
- ES 基础
You Know, for Search 安装es时 , jdk最低版本需要 jdk7 默认端口 : 9200 启动后浏览器访问 : localhost:9200 角色关系对照 elasticsear ...
- Java设计模式系列之中介者模式
中介者模式(Mediator)的定义 用一个中介对象来封装一系列的对象交互.中介者使各对象不需要显式地相互引用,从而使其耦合松散,而且可以独立地改变它们之间的交互. 中介者模式(Mediator)的适 ...
- Android实例-程序切换到后台及从后台切换到前台
相关资料: http://www.delphitop.com/html/Android/2933.html 程序包下载: http://download.csdn.net/detail/zhujian ...
- JSF 2 hidden value example
In JSF, you can use the <h:inputHidden /> tag to render a HTML hidden value field. For example ...
- JavaIO(04)字符流--Writer and Reader
字符流: 常识:在java中一个字符等于两个字节: 操作字符流的两个类:Writer,Reader API文档介绍(Writer): public abstract class Write ...
- flask前后台交互数据的几个思路
通过url进行参数传递: @app.route('/hello/<name>') # <name>为传递的参数 def hello(name=None): return ren ...
- SQLite的37个核心函数
转载:http://www.feiesoft.com/00012/ abs(X) abs(X)返回 X 的绝对值. Abs(X) returns NULL if X is NULL. Abs(X) r ...
- 【Winform】Winform 制作一键发布web
前言 最近web网站有个需要,就是打包给客户,客户能够自己手动的进行傻瓜式的安装发布web.找了很多资料,其中涉及到 文件解压 IIS操作 数据库还原 等. 发现现在就主要是两种解决方案: ①:使用V ...