shunfurh
编程介的小学生
采纳率100%
2018-12-10 03:06

一个有关于:逻辑推理方面的算法,用C语言解决,谢谢了

已采纳

Problem Description
Mike has many friends. Here are nine of them: Alice, Bob, Carol, Dave, Eve, Frank, Gloria, Henry and Irene.

Mike is so skillful that he can master n languages (aka. programming languages).

His nine friends are all weaker than he. The sets they can master are all subsets of Mike's languages.

But the relations between the nine friends is very complex. Here are some clues.

  1. Alice is a nice girl, so her subset is a superset of Bob's.
  2. Bob is a naughty boy, so his subset is a superset of Carol's.
  3. Dave is a handsome boy, so his subset is a superset of Eve's.
  4. Eve is an evil girl, so her subset is a superset of Frank's.
  5. Gloria is a cute girl, so her subset is a superset of Henry's.
  6. Henry is a tall boy, so his subset is a superset of Irene's.
  7. Alice is a nice girl, so her subset is a superset of Eve's.
  8. Eve is an evil girl, so her subset is a superset of Carol's.
  9. Dave is a handsome boy, so his subset is a superset of Gloria's.
  10. Gloria is a cute girl, so her subset is a superset of Frank's.
  11. Gloria is a cute girl, so her subset is a superset of Bob's.

Now Mike wants to know, how many situations there might be.

Input
The first line contains an integer T(T≤20) denoting the number of test cases.

For each test case, the first line contains an integer n(0≤n≤3000), denoting the number of languages.

Output
For each test case, output ''Case #t:'' to represent this is the t-th case. And then output the answer.

Sample Input
2
0
2

Sample Output
Case #1: 1
Case #2: 1024

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • caozhy 回答这么多问题就耍赖把我的积分一笔勾销了 2年前
  • qq_39950496 若逢大雪初霁 3年前

    #include
    int main(void)
    {
    int M,A,B,C,D,E,F,G,H,I;
    scanf("%d",&M);//M就是n
    if(M>3000||M int count=0;
    for(A=0;A for(B=0;B for(C=0;C for(D=0;D for(E=0;E for(F=0;F for(G=0;G for(H=0;H for(I=0;I {
    if(A>B)continue;
    if(B>C)continue;
    if(D>E)continue;
    if(E>H)continue;
    if(H>I)continue;
    if(E>C)continue;
    if(D>G)continue;
    if(G>F)continue;
    if(G>B)continue;//利用continue语句逐一验证判断条件
    count++;
    printf("COUNT=%d,A=%d,B=%d,C=%d,D=%d,E=%d,F=%d,G=%d,H=%d,I=%d",
    count,A,B,C,D,E,F,G,H,I);//逐一条件输出
    }
    return 0;
    }

    这是具体实现的步骤,输入输出格式调整一下就行

    点赞 评论 复制链接分享