编程介的小学生 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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!