Problem D: 分书问题

Problem Description

有编号分别为0,1,2,3,4的5本书,准备分给5个人A,B,C,D,E。假设5个人对5本书的阅读兴趣如下表所示。 

写一个程序,输出所有的分书方案。 

 

Input Description

Output Description

按照格式:num = n: a b c d e 输出
期中:n为方案号,从1开始;a, b, c, d, e为5个人A,B,C,D,E分到的书的编号。

#include <stdio.h>
#include <stdlib.h>
int n;
int interest[5][5] = {{0, 0, 1, 1, 0},
                      {1, 1, 0, 0, 1},
                      {0, 1, 1, 0, 1},
                      {0, 0, 0, 1, 0},
                      {0, 1, 0, 0, 1}};
int book[5]={0,0,0,0,0};
int person[5];
int divide_The_Book(int x){
    for (int i = 0; i < 5; i++) {
        if(interest[x][i]==1 && book[i]==0){
            book[i]=x+1;
            if(x==4){
                n++;
                for (int j = 0; j < 5; ++j) {
                    int temp = 0;
                    temp = book[j]-1;
                    person[temp]=j;


                }
                printf("num = %d:",n);
                for (int k = 0; k < 5; k++) {

                    printf(" %d",person[k]);


                }
                printf("\n");



            } else{
                divide_The_Book(x+1);

            }
            book[i]=0;
        }


    }
}
int main(){

    n=0;
    divide_The_Book(0);
    return 0;




};

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值