結果
問題 |
No.162 8020運動
|
ユーザー |
![]() |
提出日時 | 2015-03-08 17:58:57 |
言語 | C90 (gcc 12.3.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,814 bytes |
コンパイル時間 | 807 ms |
コンパイル使用メモリ | 23,936 KB |
実行使用メモリ | 39,680 KB |
最終ジャッジ日時 | 2024-06-24 16:10:09 |
合計ジャッジ時間 | 38,496 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 3 |
other | RE * 26 |
コンパイルメッセージ
main.c: In function ‘main’: main.c:19:17: warning: format ‘%f’ expects argument of type ‘float *’, but argument 2 has type ‘double *’ [-Wformat=] 19 | scanf("%f %f %f\n",&P0,&P1,&P2); | ~^ ~~~ | | | | float * double * | %lf main.c:19:20: warning: format ‘%f’ expects argument of type ‘float *’, but argument 3 has type ‘double *’ [-Wformat=] 19 | scanf("%f %f %f\n",&P0,&P1,&P2); | ~^ ~~~ | | | | float * double * | %lf main.c:19:23: warning: format ‘%f’ expects argument of type ‘float *’, but argument 4 has type ‘double *’ [-Wformat=] 19 | scanf("%f %f %f\n",&P0,&P1,&P2); | ~^ ~~~ | | | | float * double * | %lf main.c:18:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 18 | scanf("%d\n",&A); | ^~~~~~~~~~~~~~~~ main.c:19:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 19 | scanf("%f %f %f\n",&P0,&P1,&P2); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <stdlib.h> double dp[2][1<<14]; int BitCnt(int s){ int ret=0; int i; for(i=0;i<20;i++){ if( ((s>>i)&1)>0 )ret++; } return ret; } int main(){ double P0,P1,P2; int A; scanf("%d\n",&A); scanf("%f %f %f\n",&P0,&P1,&P2); P0/=100.0;P1/=100.0;P2/=100.0; int s,t,i; double **table; table=malloc(sizeof(double *) *(1<<14)); int Size[1<<14]; for(s=0;s<(1<<14);s++){ Size[s]=1<<BitCnt(s); table[s]=malloc(sizeof(double)*Size[s]); } for(s=0;s<1<<14;s++){ for(t=0;t<=s;t++){ if((s|t)!=s){ t+=(t&-t)-1; continue; } double p=1.0; for(i=0;i<14;i++){ if(((s>>i)&1)==0)continue; if(((t>>i)&1)==0){ if(i==0){ if(((s>>(i+1))&1)==0){ p*=P0; }else{ p*=P1; } }else{ if(((s>>(i+1))&1)==0 && ((s>>(i-1))&1)==0){ p*=P0; }else if(((s>>(i+1))&1)==1 && ((s>>(i-1))&1)==1){ p*=P2; }else{ p*=P1; } } }else{ if(i==0){ if(((s>>(i+1))&1)==0){ p*=(1.0-P0); }else{ p*=(1.0-P1); } }else{ if(((s>>(i+1))&1)==0 && ((s>>(i-1))&1)==0){ p*=(1.0-P0); }else if(((s>>(i+1))&1)==1 && ((s>>(i-1))&1)==1){ p*=(1.0-P2); }else{ p*=(1.0-P1); } } } } table[s][t]=p; } } int now=0,next=1; for(s=0;s<1<<14;s++)dp[now][s]=0.0; dp[0][(1<<14)-1]=1.0; for(i=0;i<80-A;i++){ now=i%2; next=now^1; for(s=0;s<1<<14;s++)dp[next][s]=0.0; for(s=0;s<(1<<14);s++){ for(t=0;t<=s;t++){ if((s|t)!=s){ t+=(t&-t)-1; continue; } dp[next][t]=table[s][t]*dp[now][s]; } } } double e=0; for(s=0;s<(1<<14);s++){ e+=BitCnt(s)*dp[next][s]; } printf("%.6f\n",2.0*e); for(s=0;s<(1<<14);s++){ free(table[s]); } free(table); return 0; }