Blue Bridge Cup, algorithm improvement, 8 Queen • Change

Source: Internet
Author: User

The topics are as follows:

The problem description rule is the same as the 8 queen problem, but there is a number on the board for each lattice, which requires the sum of the eight Queens to be the largest. Enter the format of a 8*8 checkerboard. The maximum number and sample input that can be obtained from the output format 1 2 3 4 5 6 7 8
9 10 11 12 13 14 15 16
17 18 19 20 21 22 23 24
25 26 27 28 29 30 31 32
33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48
48 50 51 52 53 54 55 56
57 58 59 60 61 62 63 64 Sample output 260 data size and convention number range on board 0~99 ---------Split Line-------- This problem is relatively simple, record the current all the number of the sum of the largest and then output on the line, on the question after n can go to see my previous blog.
1#include <stdio.h>2 inta[8][8];3 intvis[3][ -]={0};4 intt=0;5 intx=0;6 ints=0;7 voidDfsintcur)8 {9     inti;Ten     if(cur==8) One     { A         if(s<x) -s=x; -     } the     Else  for(i=0;i<8; i++) -     { -         if(!vis[0][i]&&!vis[1][cur+i]&&!vis[2][cur-i+8]) -         { +vis[0][i]=vis[1][cur+i]=vis[2][cur-i+8]=1; -x+=A[cur][i]; +DFS (cur+1); Avis[0][i]=vis[1][cur+i]=vis[2][cur-i+8]=0; atx-=A[cur][i]; -         } -     } - } - intMain () - { in     intI,j,max; -      for(i=0;i<8; i++) to          for(j=0;j<8; j + +) +scanf"%d",&a[i][j]); -Dfs0); theprintf"%d\n", s); *     return 0; $}

Blue Bridge Cup, algorithm improvement, 8 Queen • Change

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.