标签:des style blog http color java os io
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 647 Accepted Submission(s): 273
#include <algorithm> #include <cstring> #include <cstdio> #include <queue> #include <iostream> #include <vector> #include <string> #include <map> #include <cmath> #define REP(a,b,c) for(a=b;a<=c;a++) using namespace std; typedef long long ll; const ll inf= 1e8; const int N=52; const int M=16 ; double dp[N][5]; double p[3][3]={{0.5,0.375,0.125}, {0.25,0.125,0.625}, {0.25,0.375,0.375} }; double q[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} }; int n; int hash(string str) { if(str=="Dry")return 0; else if(str=="Dryish")return 1; else if(str=="Damp")return 2; else return 3; } int x[N],pa[N][3],ans[N]; char * weather[3]={(char*)"Sunny",(char*)"Cloudy",(char*)"Rainy"}; int run() { string str; int _,cas=0; cin>>_; while(_--) { cin>>n; for(int i=1;i<=n;++i){ cin>>str; x[i] = hash(str); } for(int i=1;i<=n;++i){ for(int j=0;j<3;++j) dp[i][j]= log(0); } memset(pa,0,sizeof(pa)); dp[1][0] = log(0.63) + log(q[0][x[1]]); dp[1][1] = log(0.17) + log(q[1][x[1]]); dp[1][2] = log(0.20) + log(q[2][x[1]]); for(int i=2;i<=n;++i) for(int j=0;j<3;++j) for(int k=0;k<3;++k){ double temp=dp[i-1][k]+log(p[k][j])+log(q[j][x[i]]); if(temp > dp[i][j] ) { dp[i][j]=temp; pa[i][j]=k; } } int pos=0; for(int i=0;i<3;++i) if(dp[n][i] > dp[n][pos]) pos=i; ans[n]=pos; for(int i=n-1;i>=1;--i){ pos=pa[i+1][pos]; ans[i]=pos; } printf("Case #%d:\n",++cas); for(int i=1;i<=n;++i) printf("%s\n",weather[ans[i]]); } return 0; } int main() { //freopen("in.txt","r",stdin); ios::sync_with_stdio(0); return run(); }
HDU 4865 Peter's Hobby,布布扣,bubuko.com
标签:des style blog http color java os io
原文地址:http://www.cnblogs.com/YRETSIM/p/3920959.html