Zoj3605 find the marble --- probability DP

Source: Internet
Author: User

There are n cups, and the ball starts at s position. m times for ball change operations, and K times for the ball. The person who looks at the Ball guesses the final position of the Ball Based on the K times he sees, the most likely output location.

DP [m] [k] [s] indicates the frequency of s when K balls are finally seen in the previous m operations.


# Include <cstdio> # include <cstring> int n, m, K, S, X [55], Y [55]; long long DP [55] [55] [55]; int main () {int I, j, L, t; scanf ("% d", & T ); while (t --) {scanf ("% d", & N, & M, & K, & S); for (I = 1; I <= m; I ++) scanf ("% d", & X [I], & Y [I]); memset (DP, 0, sizeof DP); DP [1] [0] [s] = 1; // The initial state is the position of the ball itself for (I = 1; I <= m; I ++) for (j = 0; j <= K; j ++) for (L = 1; L <= N; l ++) {If (DP [I] [J] [l]) {DP [I + 1] [J] [l] + = DP [I] [J] [l]; // I didn't see this time. // I saw this time if (L = x [I]) DP [I + 1] [J + 1] [Y [I] + = DP [I] [J] [l]; else if (L = Y [I]) DP [I + 1] [J + 1] [x [I] + = DP [I] [J] [l]; else DP [I + 1] [J + 1] [l] + = DP [I] [J] [l]; // here we also need J + 1, that is, we can see this exchange, but there is no impact} int ans = 1; for (I = 2; I <= N; I ++) if (DP [M + 1] [k] [ANS] <DP [M + 1] [k] [I]) ans = I; printf ("% d \ n", ANS);} return 0 ;}


Zoj3605 find the marble --- probability DP

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.