to judge. DFS is available, and each edge is either selected or not selected. But it has to be pruned.1#include 2 #defineLL Long Long3 #definePII pair4 #defineINF 0x7f7f7f7f5 using namespacestd;6 Const intn=Ten;7 intN, M, s[ $], e[ $], num, times[n], du[n];8 intDFS (intX//X is the first few sides9 {Ten if(num*2GT;=M)//already half enough to judge whether the requirements are met One { A for(intI=1; iif(2*du[i]!= Times[i])return 0;//Each person's degree can be half. - r
Topic Link: PortalTest instructionsGiven the two four-bit number, A, B, you can change any bit of a at a time, and make sure that the changed a is a prime.Ask at least how many times change a can become B.Analysis:BFS, the number of changes per enumeration, there is a pruning, that is, if the number of changes has been obtained before,There is no need to keep changing back to it.The code is as follows:#include POJ 3126 Prime Path (bfs+
Test instructions
There is a r*c on the matrix to select some lattice for "light" operation, so that the final lattice is "bright" state. All the squares above the initial matrix are dark, from top left to bottom, numbering starts at 1.Now let's give a 3*3 matrix, as a button rule:For example:**..*.*..That is, you press any button, the button as the center of the 3*3 Matrix, according to this rule, that is, press a button, the button around the position of the *, according to the rule,
A Math GameTime limit:2000/1000ms (java/others)Memory limit:256000/128000kb (java/others)Problem descriptionrecently, Losanto find an interesting Math game. The rule is Simple:tell you a numberH, and you can choose some numbers from a set {a[1],a[2],......, a[n]}. If the sum of the number you choose isH, then you win. Losanto just want to know whether he can win the game. Inputthere is several cases.In each case, there is numbers in the first lineN(The size of the set) andH. The second line has
indicates the strength of the Liu Bangjun.
Output file:
An integer indicates the shortest time to get out of the confused forest, if not out please output-1.
"Sample Data"
Input (road.in)
4 5
1 2 2 3
1 3 3 5
1 4 7 10
2 4 4 6
3 4 2 6
1 4
5
Output (Road.out)
11
"Data Contract"
n
[Hint]
The data is randomly generated.
"Topic ideas"
This problem is mainly search, BFS, but if only with a simple search, will definitely time out, super more than a little ...
acm_ messages
This question hdoj also has, starts to do this question, also did not think so many, directly knocks the previous code, has been tle, later learned a little new thing, does not exist has the odd number element the prime circle (each element dissimilarity). However, 1 can form a self-ring, requiring special judgment. #include #include #include #include usingnamespaceStdintN, dis[ -], vis[ -];BOOLIs_prime (intA{ if(!a | | a = =1)returnfalse;i
Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5839In a three-dimensional coordinate, give you n points, ask you how many tetrahedron (4 points, 6 edges) and satisfy at least four sides equal to the rest of the two nonadjacent.The 4 cycle of violence, but in the 3rd cycle when the need to determine whether it is isosceles triangle, this is a pruning. In the 4th cycle of the time to determine whether the 4-point coplanar (cross-multiplication),
DFS search: represent the solution space of a problem in a tree and traverse the solution space using the DFS method.
Backtracking: it refers to DFS search + pruning. Try to solve a problem step by step. In the process of solving the problem step by step, when it tries to find that the existing step-by-step answer cannot be effectively answered correctly, it will cancel the calculation of the previous step or even the previous step, then try again t
Starting from S to stopping D, and arriving at t at the specified time (not early or late ). Note that each '.' can only go once. Analysis: DFS, but common DFS and TL are used, so pruning is required. We can think that if we can arrive at, but there are other points around the D point that we can step on, and we can observe that, from a point (not a D point) if the distance from point D (ABS (X-dx) + ABS (Y-dy) is an odd number, the odd number step i
Uva10318 (dfs + pruning)
Question:
A maximum panel is provided. There are many buttons on the panel. The buttons are highlighted or not highlighted. Initially, all buttons are not highlighted. From top left to bottom right, the number starts from 1 ;,
Now we provide a 3*3 matrix as a button rule;
For example
.*.
***
.*.
That is to say, if you create a single order at any time, it is in the middle of the 3*3 matrix. According to this graph, that is, by
HDU 5113 Black And White (DFS + pruning)
Question:
Black And White
Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)Total Submission (s): 1336 Accepted Submission (s): 350Special Judge
Problem Description In mathematics, the four color theorem, or the four color map theorem, states that, given any separation of a plane into contiguous regions, producing a figure called a map, no more than four colors are required to
HDU 5113 -- Black And White (search + pruning), hdu5113 -- black
Question Link
Problem DescriptionIn mathematics, the four color theorem, or the four color map theorem, states that, given any separation of a plane into contiguous regions, producing a figure called a map, no more than four colors are required to color the regions of the map so that no two adjacent regions have the same color.
-Wikipedia, the free encyclopedia
In this problem, you hav
First of all, four Laizi to do 34*34*34*34 's poor lifting.And then do the pruning optimization.Time complexity differs by an order of magnitude 34But it's not the average efficiency, and the worst is still not going to rise too much.But some mahjong Laizi number more than 7At this point should be used to look up the table, and then the cycle to do the poor is obviously a waste of efficiencyThe relevant code is temporarily not availableYou can leave a
Original: ASP. NET Core series "two" use the entity Framework Core for additional pruning and checkingIntroduction EntityframeworkcoreEF Core is a lightweight, extensible, cross-platform version of EF. EF Core has many promotions and new features for EF, and EF Core is a brand new codebase that is not as mature and stable as EF6.EF Core maintains a similar development experience with EF, and most top-level APIs are preserved, so if you've ever used EF
"Leetcode" 814. Binary Tree Pruning problem-solving report (Python)
tags (space-delimited): Leetcode
Topic Address: https://leetcode.com/problems/binary-tree-pruning/description/ topic Description:
We are given the head node root of a binary, where additionally every node ' s value is either a 0 or a 1.
Return to the same tree where every subtree (of the given tree) is not containing a 1 has been.
(Recall
The idea of a topic is to enumerate what the situation is for each game
#include
Summarize
1: What needs to be exercised now is
Valuation function Pruning: Even if the back is what, also can not meet the conditions, here is even after the win .... (most important)
Feasibility pruning
Search order: Try to cut off when you just search
length of the bar, until the conditions to meet the output results. The scope of the enumeration is [the maximum length of a stick, the sum of the length of a stick];2, local greed: Because the longer the stick on the back of the stick of the greater the binding force, so the small stick to sort, from large to small search, so that you can be as close to the root of the place to prune;PS: Negative Pure greedy Strategy: example 10 21 14 13 11 9 6 4 3 2 1, if the greedy strategy is fully used, th
POJ 3126 Prime Path (BFS + pruning)
Question link: Portal
Question:
Given two four-digit numbers a and B, you can change any one of a at a time and ensure that the changed a is a prime number.
How many times can a be changed to B.
Analysis:
BFS, the number of changes in each enumeration, has a pruning, that is, if this number has been obtained before,
There is no need to change it back.
The Code is as follo
numbers in each list appear in nonincreasing order, and there may be repetitions. outputFor each test case, first output a line containi Ng 'sums', the total, and a colon. then output each sum, one per line; if there is no sums, output the line 'none '. the numbers within each sum must appear in nonincreasing order. A number may be repeated in the sum as usual times as it was repeated in the original list. the sums themselves must be sorted in decreasing order based on the numbers appearing in
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.