Leetcode.1005. Maximized array sum after K negations - greedy + count sorting
12.6 one question per day - maximum array sum after K inversions
Enter an array of integers and an integer k to modify the array as follows 1. Select a subscript i and replace num [i] with - num [i] 2. Repeat this process exactly k times. You can select the same subscript i multiple times. When the array is modified in this way, the maximum po ...
Posted by nicholasstephan on Mon, 06 Dec 2021 13:03:44 -0800
Greedy algorithm for single source shortest path (dijestra algorithm)
catalogue
1. Description of single source shortest path problem
2.Dijkstra algorithm idea
3. Specific case analysis
4. Specific code implementation
1. Description of single source shortest path problem
① Given weighted digraph G =(V,E). Where V is the set of all vertices in the graph. E is the set of all edges in the graph, and the ...
Posted by caster001 on Tue, 30 Nov 2021 22:49:01 -0800
Algorithm notes Chapter 7 data structure
1. Stack Simple calculator, C + + code is as follows:
#include<cstdio>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<map>
using namespace std;
struct node {
bool flag;
double num;
char op;
};
stack<node>s;
map<char,int>op;
string str;
queue<node>q;
void Cha ...
Posted by brittny85 on Tue, 30 Nov 2021 17:12:24 -0800
Teach you to play real nixie tube
Our ultimate goal is to be lazy. Working together is to see you work hard, and I am lazy to enjoy. Therefore, in order to be lazy, frame programming is inevitable. In my blog in the future, I hope everyone is frame programming. Those who are irregular should be serious and diligent. We are too lazy to be worthy of you. joy:, remember that we ar ...
Posted by nickk on Tue, 23 Nov 2021 08:40:05 -0800
Greedy algorithm C++ puzzle (leetcode101 (biscuit allocation 455 (candy allocation 135) (interval problem 435)
Basic Ideas: Local Optimal - >Global Optimal Difficulty: Determine the best "what object"
Simple questions:
Find money: a total of x Yuan with a minimum of several pieces of money 100 yuan 50 yuan 10 yuan 5 yuan 1 yuan Idea: x divides 100, 50, 20, 10, 5, 1 Integer division adds up
leetcode
455 Allocate cookies
Suppose you're a ...
Posted by amreiff on Sun, 21 Nov 2021 10:53:40 -0800
Algorithm design and analysis course - Chapter 4 greedy algorithm
Basic concepts of greedy algorithm
"First of all, it should be emphasized that the premise of 01 knapsack problem is that each item has only two states: selected and not selected. Part of an item cannot be loaded into the knapsack. This is the meaning of 01 in 01 knapsack. If a part of an item can be ...
Posted by firecat318 on Mon, 08 Nov 2021 05:48:38 -0800
A preliminary understanding of greedy thought
catalogue
1. Distribution issues
2. Interval problem
3. The best time to buy stocks
4. Summary
1. Distribution issues
Title Description:
This kind of problem probably means that there are a group of children and a pile of biscuits. Each child is very hungry. If the size of the biscuit is greater than or equal to the child's hunger, ...
Posted by DfyAnt on Wed, 03 Nov 2021 20:54:24 -0700
Codeforces Round #753 (Div. 3)
There are three main situations:
It's been a second since I took a look at my beard. The implementation is also very simple. I write casually / too lazy to write
After a second, I felt that it would not be realized, so I went to look at other people's code
I didn't understand the question
A
Direct simulation.
B
Simple math problems + find rul ...
Posted by morris on Wed, 03 Nov 2021 17:48:13 -0700
The basis of artificial intelligence - the expansion of search tree and n queen problem
Greedy Algorithm
Algorithm principle
Greedy algorithm also belongs to A heuristic algorithm. Greedy algorithm never pays attention to the whole, but always selects the optimal solution based on the current state. Greedy can be regarded as A special case of A *
In the previous blog, we already know that the comprehensive priority of A * algo ...
Posted by dopey on Wed, 27 Oct 2021 05:57:03 -0700
LeetCode buckle biweekly 63
The happiest thing at the weekend is to fill in questions and write solutions to cook for his wife.
Weekly portal
2037. Make each student have the minimum number of seat movements
Idea: greed
Time complexity:
O
(
n
∗
...
Posted by jxrd on Fri, 22 Oct 2021 19:50:27 -0700