About Me

About Me : I have been working as a Software Engineer for various international companies for four years.Currently, I am working as a full stack Javascript developer in Petronas(Malaysia).

Skills

Skills • Javascript •Typescript •Python •C •Java •ReactJs • Redux • VueJs • NestJs • React Testing Library • Django• PostgreSQL • MySQL • NodeJs • Git • Docker • Jira • Visual Studio Code • Slack

বৃহস্পতিবার, ১৭ আগস্ট, ২০১৭

UVA 167

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define READ freopen("input.txt","r",stdin)
#define ll long long
int ary[9][9];
int chk[9][9];
int mx ;

int MAX(int a,int b)
{
    return a>b?a:b;
}

bool issafe(int row,int col)
{
    for(int i=0;i<8;i++)
    {
        if(chk[row][i]==1) return false ;
    }
    for(int i=0;i<=row;i++)
        if(chk[i][col]==1) return false;
    for(int i=row,j=col;i>=0 && j>=0;i--,j--)
    {
        if(chk[i][j]==1) return false;
    }
    for(int i=row,j=col;i>=0&& j<8;i--,j++)
    {
        if(chk[i][j]==1) return false;
    }
    return true;
}
void NQ(int r,int sum)
{
    if(r==8)
    {
        mx = MAX(mx,sum);
        return ;
    }
    for(int c = 0; c<8; c++)
    {
        if(issafe(r,c))
        {
            chk[r][c] =1;
            NQ(r+1,sum+ary[r][c]);
            chk[r][c] =0;
        }
    }
}
int main()
{
    READ ;
    int test ;
    scanf("%d",&test);
    while(test--)
    {
        for(int i=0; i<8; i++)
        {
            for(int j=0; j<8; j++) scanf("%d",&ary[i][j]);
        }
        mx = -1 ;
        //clear();
        NQ(0,0);
        printf("%5d\n",mx);
    }
    return 0;
}

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন