标签:des style blog http color os io for
#include"iostream" #include"cstdio" #include"map" #include"cstring" #include"string" #include"algorithm" #include"vector" using namespace std; const int ms=51; double p1[3][4]= {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[3][3]= {0.5,0.375,0.125,0.25,0.125,0.625,0.25,0.375,0.375}; double dp[ms][3]; int pre[ms][3]; map<int,string> m1; map<string,int> m2; string str; void init() { m2.insert(make_pair("Dry",0)); m2.insert(make_pair("Dryish",1)); m2.insert(make_pair("Damp",2)); m2.insert(make_pair("Soggy",3)); m1.insert(make_pair(0,"Sunny")); m1.insert(make_pair(1,"Cloudy")); m1.insert(make_pair(2,"Rainy")); } int main() { int ncase,T=0; scanf("%d",&ncase); init(); while(ncase--) { printf("Case #%d:\n",++T); int n,i,j,k; scanf("%d",&n); cin>>str; for(i=0;i<=n;i++) for(j=0;j<3;j++) dp[i][j]=0; int lab=m2[str]; memset(pre,0,sizeof(pre)); dp[1][0]=0.63*p1[0][lab]; dp[1][1]=0.17*p1[1][lab]; dp[1][2]=0.2*p1[2][lab]; for(i=2;i<=n;i++) { cin>>str; lab=m2[str]; for(j=0;j<3;j++) for(k=0;k<3;k++) { double pp=dp[i-1][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=0; int po; for(i=0;i<3;i++) if(dp[n][i]>mi) { mi=dp[n][i]; po=i; } ans.push_back(po); int now=n; while(now!=1) { po=pre[now][po]; ans.push_back(po); now--; } for(i=n-1;i>=0;i--) { //printf("%s\n",m1[ans[i]]); cout<<m1[ans[i]]<<endl; } } return 0; }
标签:des style blog http color os io for
原文地址:http://www.cnblogs.com/767355675hutaishi/p/3895248.html