标签:des style blog http io ar 使用 for strong
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 5093 | Accepted: 1385 |
Description
Input
Output
Sample Input
1 0.5 2 2 0.5 2 4
Sample Output
0.5000000 0.2500000
Source
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; struct node { double x , y ; double a[2][2] ; } s , k ; node f(node p,node q) { node k ; int i , j , l ; k.x = p.x ; k.y = q.y ; for(i = 0 ; i < k.x ; i++) { for(j = 0 ; j < k.y ; j++) { k.a[i][j] = 0 ; for(l = 0 ; l < p.y ; l++) k.a[i][j] += p.a[i][l]*q.a[l][j] ; } } return k ; } node pow(node p,int m) { node q ; q.x = q.y = 2 ; q.a[0][0] = q.a[1][1] = 1 ; q.a[0][1] = q.a[1][0] = 0 ; if(m == 0) return q ; q = pow(p,m/2); q = f(q,q); if( m%2 ) q = f(q,p); return q; } int main() { int n , i , j , a[12] , m , flag; double p ; while(scanf("%d %lf", &n, &p)!=EOF) { flag = a[0] = 0 ; for(i = 1 ; i <= n ; i++) { scanf("%d", &a[i]); if(a[i] == 1) flag = 1 ; } if(flag) { printf("0.0000000\n"); continue ; } sort(a,a+n+1); s.x = 2 ; s.y = 1 ; s.a[0][0] = 1 ; k.x = k.y = 2 ; k.a[0][0] = p ; k.a[0][1] = (1-p) ; k.a[1][0] = 1 ; k.a[1][1] = 0 ; for(i = n-1 ; i >= 0 ; i--) { s.a[1][0] = s.a[0][0] ; s.a[0][0] = 0 ; m = ( a[i+1]-1-a[i] ) ; s = f(pow(k,m),s); } printf("%.7lf\n", s.a[0][0]); } return 0; }
poj3744--Scout YYF I(概率dp第五弹:矩阵优化)
标签:des style blog http io ar 使用 for strong
原文地址:http://blog.csdn.net/winddreams/article/details/40502705