DescriptionIn a given shape of the chessboard (the shape may be irregular) on the top of the pieces, chess pieces no difference. If you need to place any of the two pieces in the same row or column in the chessboard, please program the chessboard with a given shape and size, and put all the feasible arrangement C for the K pieces.InputThe input contains multiple sets of test data.The first row of each set of data is two positive integers, n K, separated by a space, indicating that the chessboard
[i]) { - for(intj =1; J //look for "#" in the line to if(Map[i][j] = ='#' Row[j] = =0) { +Chose[i] = j;//The first t piece is placed in the J position of line I -ROW[J] =1; theChessdfs (t +1); *ROW[J] =0; $ }Panax Notoginseng } - } the } + } A } the + intCheckintk) { - for(inti =1; I ) { $ if(Map[k][i] = ='#' Chose[k])return 1; $ } - return 0; - } the - voidLinedfs (intt) {Wuyi
answer is to see the board on the odd number of or even a number of black pieces;AC Code:#include /*#include */using namespacestd;#defineRiep (n) for (int i=1;i#defineRIOP (n) for (int i=0;i#defineRJEP (n) for (int j=1;j#defineRJOP (n) for (int j=0;j#defineMST (SS,B) memset (ss,b,sizeof (ss));typedefLong LongLL;ConstLL mod=1e9+7;Const DoublePi=acos (-1.0);ConstLL inf=1e18;Const intn=1e5+4;intn,m,a[ the][ the];intMain () {intT; scanf ("%d",t); while(t--) {scanf ("%d%d",n,m); intsum=0; Riep (n)
DescriptionIn a given shape of the chessboard (the shape may be irregular) on the top of the pieces, chess pieces no difference. If you need to place any of the two pieces in the same row or column in the chessboard, please program the chessboard with a given shape and size, and put all the feasible arrangement C for the K pieces.InputThe input contains multiple sets of test data.The first row of each set of data is two positive integers, n K, separated by a space, indicating that the chessboard
Title: Give an n * N chess board, there are some places on this board can not play chess pieces.Now ask you to put a K on this board, so that any of these pieces of two not on the same row, ask how many waysProblem-solving ideas: Similar to the N-queen, can be a line of processing, with the binary 1 means that the position can be put, 0 means no, all indicates the status of each row can be put ((1 Assuming the state of the column is S, then S (the line's limit) All is the end state of the row.
http://poj.org/problem?id=1321Because the search is originally written, and the training time did not come so can only now fill the-_-A simple deep search#include #includestring.h>#include#include#defineN 10#defineINF 0XFFFFFFF#include#includeusing namespacestd;intN,ans,k,num,vis[n],sx,sy;CharMaps[n][n];voidDfsintM//M is the first few lines;{ inti; if(num==k) {ans++; return ; } if(m>=N)return ; for(i=0; i) { if(vis[i]==0maps[m][i]=='#') {num++; Vis[i]=1; DFS (M+1); Vis[i]=0; Num
Reprint please indicate the source CSDN ametake All rights reservedTitle Description DescriptionThe number triangle must pass a certain point to make it go the distance and the maximumEnter a description input DescriptionRow 1th N, representing n rows2nd to n+1 behavior each weight valueThe program must go through the N Div 2,n Div 2 pointOutputs description output DescriptionMaximum ValueSample input to sample211 1Sample output sample outputs2Data size HintN Listen to Lu Jinglong god Ben tod
An n * N chess board, some lattices can not put, put the pieces of M,each of the two pieces cannot be in the same row or column, ask how many kinds of release methodDfs is too slow, use SCR better dotPython has only 22 lines, which in fact can be shorter. But it's going to be a very long, very long line.While true:table = [[0 to J in Range] ' for I in range ()] table[0][0] = 1 boardsize, chessnum = ma P (int, raw_input (). Split ()) if boardsize = = Chessnum = -1:break states = Range (1 Dynamic
In a given shape of the chessboard (the shape may be irregular) on the top of the pieces, chess pieces no difference. If you need to place any of the two pieces in the same row or column in the chessboard, please program the chessboard with a given shape and size, and put all the feasible arrangement C for the K pieces.-------------------------------------------------------------------#include#include#include#include#includeint MN;Char Str[105][105];int dir[8][2]={{1,1},{-1,1},{-1,-1},{1,-1}};in
number of pieces to be placed. N When 1-1 indicates the end of the input.The following n-line description describes the shape of the chessboard: N characters per line, where # indicates the board area. Represents an empty area (the data guarantees that no extra blank lines or blank columns appear).OutputFor each set of data, give a line of output, the output is placed in the number of programs C (Data Assurance cSample Input2 #.. #4 4...#. #.. #.. #...-1-1Sample Output21stThe code is as follows
(Maxval, Dp[x1][y1][x2][y2]); the } About } the } theDP[I][J][K][L] = max (Dp[i][j][k][l], Maxval + arr[i][j] +arr[k][l]); the } + } - } the //two path to reach Point [M][n], then the point of the two path must choose: [M][n-1],[m-1][n]Bayi intans = max (Dp[m][n-1][m-1][n], Dp[m-1][n][m][n-1]); the //for (int i = 1; I the //{ - //For (int j = 1; j - // { the //for (int k = 1; k
] +arr[i][j]);Wuyi } the if(Check (x2, y2, I-1)) - { WuDP[I][J] = max (Dp[i][j], Dp[x2][y2] +arr[i][j]); - } About } $ } - /*for (int i = 1; I - { - For (int j = 1; J A { + cout the } - }*/ $cout 1) Endl; the } the the intMain () the { - #ifdef HOME inFreopen ("inch","R", stdin); the //freopen ("Out", "w", stdout); the #endif About for(inti =0; i i) the { the for(intj =0; J j) the
pieces we need to place, and then ask us how to put them in several ways. First we can make it clear that this is a topic of deep search, similar to the eight Queens question. We create a function Dfs is used to accumulate the number of feasible scenarios, we walk through a column we will mark it down the next time we can not be placed in this column (because the title is not allowed to be placed in the same row and the same column)Then start looking for a viable place from the next line, until
(Visi,0,sizeof(Visi)); memset (VISJ,0,sizeof(VISJ)); memset (Vis1,0,sizeof(VIS1)); memset (Vis2,0,sizeof(VIS2)); if(Dfs (0,0,0)) Break; } printf ("Case %d:%d\n",++Cas,maxd); } return 0;}The first kind of pruning3. You can place rows (or columns) on a row-by-line basis. There is also a pruning is up to 5, so maxd==4 has no solution, direct output 5.0.201s#include #includeConst intMAXN = One;CharG[MAXN][MAXN];intMaxd;intn,m;BOOLvisi[maxn],visj[maxn],vis1[maxn1],vis2[maxn1];BOOLDfsintDintsi) {
So simple a topic, thought for so long, also WA once, unforgivable ah, more and more feel stupid, Dfs search will not write ... LuoConfusion, we must seriously think about the topic, seriously write code:Code:#include Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. POJ 1321 Checkerboard Problem Simple DFS
One, test instructions:Chinese questionsSecond, analysis:The main use of compressed DP and memory search ideasThree, code:#include Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. POJ 1191 Checkerboard Segmentation (compression dp+ memory Search)
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.