编程介的小学生 2019-02-05 21:16 采纳率: 20.5%
浏览 328

采用投影法计算二维字符串权重概率判定问题,C语言设计的实现

Problem Description
Mr.Panda did a survey among N candidates.
In the survey, each candidate was given a questionnaire which contains M yes/no questions. It is guaranteed that each question was answered with a “Yes” or a “No” by each candidate.
Mr.Panda likes variety. He considers a question as a good question if there are at least one candidate answered “Yes” and at least one candidate answered “No” for that question.
Now Mr.Panda has collected all the questionnaires. He wants to do some statistical analysis based on the survey result.
Because Mr.Panda is super lazy, he wants to randomly pick some of the questionnaires as a sample.
For each possible subset of questions (excluding empty set), Mr.Panda wants to know the probability that all questions in the subset are good questions, assuming that questionnaires in the sample are chosen randomly so that sample can be any subset (including full set and empty set) of questionnaires with equal probability.
Could you help Mr.Panda solve this problem?
To simplify the problem, you are only required to calculate ( P1⋅2N mod 1000000007) ⊕ ( P2⋅2N mod 1000000007) ⊕ · · · ⊕ ( P2M−1· 2N mod 1000000007)
where Pi means the probability of i th subset of questions to be good questions. It is obvious that Pi⋅2N is always an integer.
“⊕” which is known as “bitwise exclusive or” corresponds to operator “^”in both C/C++ and Java.
“ mod ” which is known as “modulo” corresponds to operator “%” in both C/C++ and Java.

Input
The first line of the input gives the number of test cases, T.
T test cases follow. Each test case consists of two lines. The first line contains two integers N, the number of questionnaires, and M, the number of questions.
The second line contains N strings Q1,Q2,...,QN representing the answers in each questionnaire.
Each questionnaire Qi is given in the form of exact M charecters where each character can be either “Y” standing for “Yes” or “N” standing for “No”.

Output
For each test case, output one line containing “Case #x: y”, where x is the test case number(starting from 1) and y is the xor sum of the weighted probabilities.
limits

∙1≤T≤20.
∙1≤N≤105.
∙1≤M≤15.

Sample Input
2
2 2
NY YN
4 2
NN NY YN YY

Sample Output
Case #1: 1
Case #2: 7

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料