UVa 167 successor of the Sudan

Source: Internet
Author: User

Test instructions: Similar to the 8 queen question, except that each lattice on the board has a score and the Queen's position is the one that can be obtained. Or the rule of the 8 Queen's question, and finally get the best possible score.

Idea: 8 Queen problem solution, after 8 Queens to judge the score on the line.

In the If statement judgment content that piece unexpectedly still write wrong once, not satisfied ~

You can also use vis[3][2*8]; array markers, and then quickly

Code:

#include <stdio.h>void dfs (int cur,int score), int chess[8][8];int bestscore;int c[8];int main () {  //freopen (" 167.in "," R ", stdin);  Freopen ("167.out", "w", stdout);      int k;  scanf ("%d", &k);  while (k-->0)  {    for (int. i=0;i<8;++i)      for (int j=0;j<8;++j)      {        scanf ("%d", &chess[i] [j]);      }    bestscore=0;    DFS (0,0);    printf ("%5d\n", Bestscore);  }  return 0;} void Dfs (int cur,int score) {  if (cur==8)  {    bestscore=score>bestscore?score:bestscore;  }  else for  (int i=0;i<8;++i)//try each column   {    c[cur]=i;    int ok=1;    for (int j=0;j<cur;++j)//The following if statement is cur instead of I ...       if (C[cur]==c[j] | | | C[cur]+cur==c[j]+j | | C[CUR]-CUR==C[J]-J) {ok=0; break;}      if (OK)    {      dfs (cur+1,score+chess[cur][c[cur]);}       }      }


UVa 167 successor of the Sudan

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.