1174 Target Sudoku
2009 Noip National League Improvement Group
time limit: 4 sspace limit: 128000 KBtitle level: Diamonds Diamond SolvingTitle Description
Description
Small city and Xiao Hua are good students who love maths, recently, they have been fascinated by Sudoku game, competitive he
We want to use Sudoku to a high and low. But the ordinary Sudoku was too simple for them, so they asked Dr. Z for advice,
Dr. Z took out his recently invented "target Sudoku" as a contest for the two children.
The square of the target Sudoku is the same as the ordinary Sudoku, and in the large nine lattice with a width of 9 x9, there are 9 3 squares wide x3 lattice.
The height of the small nine Gongge (separated by a coarse black line). In this large nine lattice, some numbers are known, according to these
Numbers, using logical reasoning, to fill the other blanks with numbers from 1 to 9. Each number in a small nine lattice cannot be
Repeat, each number cannot be repeated in each row or column. But the unique point of the target is different from the ordinary Sudoku, i.e.
Each square has a score, and as with a target, the closer the center is, the higher the score.
The specific score distribution is: the innermost one (yellow area) is 10 points, the yellow area outside the circle (red
Color area) Each grid is 9 points, then the outer circle (blue area) is 8 points each, the blue area outside a circle (brown
Color area) Each grid is 7 points, and the outermost lap (white area) is 6 points each, as shown in. of the game
Requirements are: Each person must complete a given sudoku (each given Sudoku may have a different fill), and to fight for
A higher total number of points. And this total score is the number of points on each square and the numbers that are filled in on the corresponding grid when the Sudoku is completed.
The sum of the product of the. , the total score is 2829 in the following list of target Sudoku games that have been filled with numbers. Swim
Play rules, will be the total number of high and low to decide the outcome.
Because of the need to win, small city found good at programming you, let you help him to find out, for a given target number of Sudoku, can
To get the highest score.
Enter a description
Input Description
Altogether 9 lines. 9 integers per line (each of which is in the range of 0-9), representing a sudoku that has not yet been filled
Blank spaces are denoted by "0". Each of the two numbers is separated by a space.
Output description
Output Description
The output can be obtained by the highest score of the target Sudoku. If this sudoku is not solved, the output integer-1.
Sample input
Sample Input
"Input and output Example 1"
7 0 0 9 0 0 0 0 1
1 0 0 0 0 5 9 0 0
0 0 0 2 0 0 0 8 0
0 0 5 0 2 0 0 0 3
0 0 0 0 0 0 6 4 8
4 1 3 0 0 0 0 0 0
0 0 7 0 0 2 0 9 0
2 0 1 0 6 0 8 0 4
0 8 0 5 0 4 0 1 2
"Input and output Example 2"
0 0 0 7 0 2 4 5 3
9 0 0 0 0 8 0 0 0
7 4 0 0 0 5 0 1 0
1 9 5 0 8 0 0 0 0
0 7 0 0 0 0 0 2 5
0 3 0 5 7 9 1 0 8
0 0 0 6 0 1 0 0 0
0 6 0 9 0 0 0 0 1
0 0 0 0 0 0 0 0 6
Sample output
Sample Output
"Input and output Example 1"
2829
"Input and output Example 1"
2852
Data range and Tips
Data Size & Hint
"Data Range"
40% of the data, the number of non-0 number of Sudoku is not less than 30.
80% of the data, the number of non-0 number of Sudoku is not less than 26.
100% of the data, the number of non-0 number of Sudoku is not less than 24.
Category labels
Tags Click here to expandHeuristic Search search Mainland region Noip National League increase Group 2009
Puzzle : A template for heuristic search
AC Code:
#include <cstdio>#include<cstring>#include<iostream>using namespaceStd//I use 1-10, you can use 0-9, the sameintfs[Ten][Ten]={{0,0,0,0,0,0,0,0,0,0},//the title says-score{0,6,6,6,6,6,6,6,6,6}, {0,6,7,7,7,7,7,7,7,6}, {0,6,7,8,8,8,8,8,7,6}, {0,6,7,8,9,9,9,8,7,6}, {0,6,7,8,9,Ten,9,8,7,6}, {0,6,7,8,9,9,9,8,7,6}, {0,6,7,8,8,8,8,8,7,6}, {0,6,7,7,7,7,7,7,7,6}, {0,6,6,6,6,6,6,6,6,6}};intnum[Ten][Ten]={{0,0,0,0,0,0,0,0,0,0},//partition, 9-small nine lattice{0,1,1,1,2,2,2,3,3,3}, {0,1,1,1,2,2,2,3,3,3}, {0,1,1,1,2,2,2,3,3,3}, {0,4,4,4,5,5,5,6,6,6}, {0,4,4,4,5,5,5,6,6,6}, {0,4,4,4,5,5,5,6,6,6}, {0,7,7,7,8,8,8,9,9,9}, {0,7,7,7,8,8,8,9,9,9}, {0,7,7,7,8,8,8,9,9,9}};intc[Ten][Ten];//Operations-ArraysBOOLf1[Ten][Ten],f2[Ten][Ten],f3[Ten][Ten];structnode{intx, y;} jl[ the];intAns,maxans;voidDfsintN) { if(!N) { if(Maxans<ans) Maxans=ans;//iterate through all the situations that can constitute sudoku, taking the optimal return ; } inti=jl[n].x;//start to fill the number intj=jl[n].y; for(intk=1; k<=9; k++) {//enumeration of 1-9 of the number of children if(!f1[i][k]&&!f2[j][k]&&!F3[num[i][j]][k]) {F1[i][k]=1; F2[J][K]=1; F3[NUM[I][J]][K]=1; C[I][J]=K; Ans+=k*Fs[i][j]; DFS (n-1);//SearchANS-=K*FS[I][J];//Backtrackingf1[i][k]=0; F2[J][K]=0; F3[NUM[I][J]][K]=0; } }}intMain () {intn=0; for(intI=1; i<=9; i++) for(intj=1; j<=9; j + +) {scanf ("%d",&C[i][j]); if(C[i][j]) {F1[i][c[i][j]]=1;//mark that the line cannot be filled with c[i][j] equal numbers.f2[j][c[i][j]]=1;//flag that the column cannot be filled with c[i][j] equal numbers.f3[num[i][j]][c[i][j]]=1;//mark the small nine to be no more than the number of c[i][j] equal.ANS+=C[I][J]*FS[I][J];//record an existing score } Elsejl[++n].x=i,jl[n].y=j;//record the position and number of ' 0 '} dfs (n); for(intI=1; i<=9; i++) for(intj=1; j<=9; j + +) if(!c[i][j]) {//Obviously, the construction of Sudokuprintf"-1\n");return 0; } printf ("%d\n", Maxans);//Maximum total number of points return 0;}
1174 Target Sudoku