Codeforces 482C Game with Strings

Source: Internet
Author: User

Serie A champions:

n the probability of the string being hidden by a certain length m string equality then, you guess how the player hides the string of the query string in a position where the gamer will be able to determine what the hidden string is and ask the gamer for the desired number of steps

Ideas:

Can be said to be a probability problem can also be said to be expected to have a good title in short ...

First, let's say we enumerate which of the hidden strings (complexity N) and then use the shape to press the DP to maintain the probability of guessing the state of certain bits and the number of strings that are indistinguishable from that state (complexity m*2^m) so the complexity is O (nm2^m) and that will be tle.

Then think about the fact that the problem is not on the 2^m of the pressure (it's already very good) since I don't get rid of the pressure, then the auxiliary state transfer of M also can't throw away we can only think of ways to avoid that n to make the complexity O (m2^m)

Then we'll determine the scenario:

We use the binary number of the pressure to indicate where the M position has been revealed. Then we can use DP to find out the probabilities for each state (or the expectation that one does not reveal to the present state), then it is now possible to guess which string is hidden in this state hypothesis. Then we don't have to guess, or at least guess the next step. This "next" contribution to the entire game's expected steps is dp[state]*1

Now, the question is, how do you infer that this state is over?

In fact, this problem can be used in DP to chart out what has been guessed some position after the string is now the state cannot be resolved (f array in the code)

So assuming that f is 0, it is assumed that the assumption is not 0, and that there are at least 2 1 present, and for each of the 1, it would be 1 steps to hide the corresponding string, and 1 step to the answer is the dp[]*1.

Code:

#include <cstdio> #include <iostream> #include <cstring> #include <string> #include < algorithm> #include <map> #include <set> #include <vector> #include <queue> #include < cstdlib> #include <ctime> #include <cmath> #include <bitset>using namespace std;typedef long Long LL ; #define N 55#define M 25int N, Len;char str[n][m]; LL f[(1 << +), Bin[n];d ouble ans[(1 <<) + ten];d ouble res;int main () {int I, j, K, c;bin[0] = 1;for ( i = 1; i < N; i++) Bin[i] = (Bin[i-1] << 1); scanf ("%d", &n), for (i = 0; i < n; i++) scanf ("%s", Str[i]); len = strlen (str[1] for (i = 0, i < n; i++) {for (j = 0; J < N; j + +) {if (i! = j) {int same = 0;for (k = 0; k < Len; k++) {if (str[ I][k] = = Str[j][k]) same |= bin[k];} F[same] |= bin[j];}} for (i = Bin[len]-1, i >= 0, i--) {for (j = 0; J < Len; J + +) {if (I & Bin[j]) {f[i ^ bin[j]] |= f[i];}} Ans[0] = 1;for (i = 0; i < Bin[len]; i++) {for (c = j = 0; J < lEn J + +) {if (I & Bin[j]) C + +;} for (j = 0; J < Len; J + +) {if (! ( I & Bin[j])) ans[i | bin[j]] + + ans[i]/(LEN-C);} for (j = 0; J < N; j + +) {if (F[i] & Bin[j]) res + = Ans[i];}} printf ("%.10f\n", res/n); return 0;}


Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

Codeforces 482C Game with Strings

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.