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 ...
随机推荐
- Hibernate逆向工程
MySQL Administrator 创建表 MyEclipse Database Explorer视图: 1. New 2 .Driver template: MySQL Connector ...
- CSS_网站配色参考方案
http://www.cnblogs.com/QLeelulu/archive/2008/04/04/1136974.html Shiny silver [#EEEEEE] Reddi ...
- System.Rtti.TRttiObject.GetAttributes 简例
MAttribute = class(TCustomAttribute) private FName: string; public constructor Create(AName: string) ...
- hello, angular
开始系统学习一下angular!首先是hello world.根据官网给出的例子,我们一下做出下面这个东西: <!DOCTYPE html> <html ng-app> < ...
- uLua学习笔记(三):Unity3D和Lua之间的相互调用
这篇笔记主要集中学习一下uLua和Unity3D之间相互调用的方法,我们导入了uLua之后,现在会弹出一个类似学习屏幕的东西,如下: 先赞一个! Unity3D调用Lua Unity3D调用Lua的方 ...
- STM32实验非正式报告之DMA
前言 DMA即直接内存存取.我理解它就是一个“交通部长”抑或是一个“搬运工”,协助CPU存储或读取数据.既然它的主要工作就是“搬运”数据,服务对象自然就是内存(不太严格的说法吧,STM32中Flash ...
- Oracle数据库的版本变迁功能对比
Oracle数据库自发布至今,也经历了一个从不稳定到稳定,从功能简单至强大的过程.从第二版开始,Oracle的每一次版本变迁,都具有里程碑意义. 1979年的夏季,RSI(Oracle公司的前身,Re ...
- 部署WEB应用程序
部署WEB应用程序: 1.在模板机上新建IIS站点 2.安装WebDeploy后在IIS控制台中导出站点为应用程序包 其站点在新虚机上必须存在,否则会报错,如下: 应用程序(C:\ProgramDat ...
- windows 下实现函数打桩:拦截API方式
windows 下实现函数打桩:拦截API方式 近期由于工作须要,開始研究函数打桩的方法. 由于不想对project做过多的改动,于是放弃了使用Google gmock的想法. ...
- python flask 部署
flask在开发的时候,经常启动本身进行调试(本身可以设置监听的端口,例如 在app.run(port=8088),当然默认不设置端口为5000). 但生产环境经常使用uswgi充当flask的宿主, ...