解决方案 »

  1.   


    public class myt5 
    {
    static int[][]  num=new int[5][7];
    static int a=0;
    static int a1=0;
    static int a2=0;
    static int a3=0;
    static int a4=0;
    static int a5=0;
    static int a6=0;
    public static void main(String[] args) 
    {
    for (int i = 0; i < num.length; i++) {
    for (int j = 0; j < num[i].length; j++) {
    num[i][j]=0;
    }
    }
    f(num,0,0);
    System.out.println(a1+"+"+a2+"+"+a3+"+"+a4+"+"+a5+"+"+a6+"=="+(a1+a2+a3+a4+a5+a6));
    System.out.println(a);
    }
    public static void f(int [][] n,int x,int y)
    {
    int[][]  s=new int[5][7];
    for (int i = 0; i < s.length; i++) {
    for (int j = 0; j < s[i].length; j++) {
    s[i][j]=n[i][j];
    }
    }
    if(x>4&&y>6)
    {
    a++;
    panduan(s);
    return;
    }
    else if(x==4&&y==6)
    {
    f(s,x+1,y+1);
    s[x][y]=1;
    f(s,x+1,y+1);
    }
    else if(x==4)
    {
    f(s,x,y+1);
    s[x][y]=1;
    f(s,x,y+1);
    }
    else if(y==6)
    {
    f(s,x+1,y);
    s[x][y]=1;
    f(s,x+1,y);
    }
    else
    {
    f(s,x+1,y);
    f(s,x,y+1);
    f(s,x+1,y+1);
    s[x][y]=1;
    f(s,x+1,y);
    f(s,x,y+1);
    f(s,x+1,y+1);
    }

    } public static void panduan(int[][] n) 
    {

    /*
      //1. 所有人的连续工作日不能多于3天(注意:周日连到下周一也是连续)。
         //2. 一周中,至少有3天所有人都是上班的。
         //3. 任何一天,必须保证 A B C D 中至少有2人上班。
         //4. B D E 在周日那天必须休息。
         //5. A E 周三必须上班。
         //6. A C 一周中必须至少有4天能见面(即同时上班)。
     */

    //1. 所有人的连续工作日不能多于3天(注意:周日连到下周一也是连续)。
    for (int i = 0; i < n.length; i++)
    {
    int start=0;
    int end=0;
    int count=0;
    int temp=0;
    boolean tem=true;
    for (int j = 0; j < n[i].length; j++)
    {
    if(count>=3)
    {
    a1++;
    return;
    }
    if(j==0)
    {
    count=1;
    temp=n[i][j];
    }
    else
    {
    if(n[i][j]==temp)
    {
    count++;
    }
    else
    {
    count=1;
    temp=n[i][j];
    if(tem)
    {
    start=count;
    tem=false;
    }
    }
    }
    if(j == n[i].length-1)
    {
    end=count;
    }
    }
    if(start+end>=3)
    {
    a1++;
    return;
    }
    }
    //2. 一周中,至少有3天所有人都是上班的。
    for (int i = 0; i < n[0].length; i++) 
    {
    int s=7;
    for (int j = 0; j < n.length; j++) 
    {
    if(n[j][i]==0)
    {
    s--;
    }
    }
    if(s<3)
    {
    a2++;
    return;
    }
    }

         //3. 任何一天,必须保证 A B C D 中至少有2人上班。
    for (int i = 0; i < n[0].length; i++) 
    {
    if(n[0][i]+n[1][i]+n[2][i]+n[3][i]<2)
    {
    a3++;
    return;
    }
    }

         //4. B D E 在周日那天必须休息。

    if(n[1][6]==1||n[3][6]==1||n[4][6]==1)
    {
    a4++;
    return;
    }
         //5. A E 周三必须上班。
    if(n[0][2]==0||n[4][2]==0)
    {
    a5++;
    return;
    }
         //6. A C 一周中必须至少有4天能见面(即同时上班)。
    int t=0;
    for (int i = 0; i < n[0].length; i++) 
    {
    if(n[0][i]==1&&n[2][i]==1)
    {
    t++;
    }
    }
    if(t<4)
    {
    a6++;
    return;
    }

    for (int i = 0; i < n.length; i++)
    {
    for (int j = 0; j < n[i].length; j++)
    {
    System.out.print(n[i][j]);
    }
    System.out.println();
    }

    }




    }