Poj 3744 scout yyf I probability DP matrix was initially considered wrong TLE

Source: Internet
Author: User
# Include <cstdio> # include <cstring> # include <algorithm> using namespace STD; // high-precision note-0.000000 // note for disordered input struct matrix {int N, m; double mat [2] [2]; void clear (void) {memset (MAT, 0, sizeof (MAT);} void get_e (void) {int I = 0; clear (); for (I = 0; I <n; I ++) mat [I] [I] = 1;} matrix () {clear () ;}matrix (int x, int y): n (x), m (y) {clear ();}}; matrix Operator * (const Matrix & A, const Matrix & B) {int I, j, k; matrix RET (. n, B. m); For (k = 0; k <. m; k + +) For (I = 0; I <A. N; I ++) if (A. Mat [I] [k]! = 0) for (j = 0; j <B. m; j ++) ret. mat [I] [J] + =. mat [I] [k] * B. mat [k] [J]; return ret;} matrix MYPOW (matrix A, int X) {matrix RET (. n,. m); If (x <0) return ret; ret. get_e (); While (x) {If (X & 1) ret = RET * A; A = A * A; X >>=1;} return ret ;} const int LMT = 12; int POS [LMT]; int main (void) {int N; Double P, ans; matrix TEM (2, 1), use (2, 2); While (~ Scanf ("% d % lf", & N, & P) {for (INT I = 1; I <= N; ++ I) scanf ("% d ", & amp; POS [I]); sort (Pos, POS + n + 1); TEM. clear (); TEM. mat [1] [0] = 1.0; use. mat [1] [1] = P; use. mat [1] [0] = 1-P; use. mat [0] [1] = 1; for (INT I = 1; I <= N; I ++) {ans = (MYPOW (use, pos [I]-pos [I-1]-2) * TEM ). mat [1] [0]; ans * = (1-p); TEM. clear (); TEM. mat [1] [0] = ans;} If (ANS <0) ans = 0; printf ("%. 7f \ n ", ANS);} return 0 ;}

Incorrect at first, TLE

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.