ue 抗锯齿 渲染序列失灵_最大的锯齿形序列

ue 抗锯齿 渲染序列失灵

Problem statement:

问题陈述:

Given a square matrix of size n x n, find the sum of the Zigzag sequence with the largest sum. A zigzag sequence starts from the top and ends at the bottom. Two consecutive elements of sequence cannot belong to the same column.

给定大小为nxn的方阵, 找到Zigzag序列的总和最大之字形序列从顶部开始,在底部结束。 序列的两个连续元素不能属于同一列。

    Input:
First line contains an integer N denoting the size of the matrix. 
Then in the next line are N*N space separated values of the matrix.
Output:
Print the required max sum.
Constraints:
1<=N<=100
1<=M[][]<=1000

Example:

例:

    Input:
Input matrix
3 8 2
4 8 5
6 9 7
Output: 22
Maximum Zigzag sequence is: 
8->5->9
Other sequences can be: 
3->8->6 etc.
Input:
Input matrix
3  2  1
10 8  5 
6  6  4
Output: 18
In the above also, the maximum zigzag sequence will be:
2->10->6

The second example clearly shows that the greedy solution wouldn't work. Let's say we opt for greedy technique and as a measure, what we do is to extract local maximum, i.e., to extract maximum out of this row and the go-ahead to the next row and find out maximum skipping the column where we found our last maximum.

第二个例子清楚地表明,贪婪的解决方案是行不通的。 假设我们选择贪婪技术,并且作为一种度量,我们要做的是提取局部最大值,即从该行中提取最大值,然后继续到下一行,并找出最大值,跳过找到我们的列最后的最大值。

So if we follow a similar approach, let's check what we can lead to.

因此,如果我们采用类似的方法,那么让我们检查一下会导致什么。

So, firstly, we will pick 3 out of the first row (0th row)

因此,首先,我们将从第一行( 0行)中选择3

From the next row, we will pick 8 as we can't peek 10 due to out constraint.

在下一行中,我们将选择8 ,因为由于出局限制我们无法窥视10

And from the next row, we will pick (of 0th column)

然后从下一行中,选择6 ( 0列)

So it sums up to 3+8+6 which is 17. But it's wrong we know output would be 18. So finding local best doesn't lead to global best. Hence, greedy will not work here.

因此,总和为3 + 8 + 6 ,即17 。 但是我们知道输出为18是错误的。 因此,找到本地最佳并不能带来全球最佳。 因此,贪婪在这里不起作用。

We need dynamic programing or recursion to solve.

我们需要动态编程或递归来解决。

Solution Approach:

解决方法:

So, let's see what can be a recursive solution. Then, we will check for overlapping sub-problems and will gradually optimize the recursion by memorization.

因此,让我们看看什么是递归解决方案。 然后,我们将检查重叠的子问题,并通过记忆逐步优化递归。

Let the recursive function be, recurZigzag(matrix, currow, curcolulm, n)

设递归函数为recurZigzag(matrix,cur row ,cur colulm ,n)

    Function recurZigzag(matrix,currow,curcolulm):
If (currow reaches n)
Return 0;
for i=0 to n except curcolumn
Return  matrix[currow][curcolumn] + max(recurZigzag(matrix, currow + 1, i))
End Function
// In the main function
for column=0 to n-1
result=max⁡(result,recurZigzag(matrix,0,column)

So what we did?

那我们做了什么?

We are starting from each column on the top row.

我们从第一行的每一列开始。

Then we are recursively checking for the next row skipping the current column. So, this checks all combinations possible.

然后,我们递归地检查跳过当前列的下一行。 因此,这将检查所有可能的组合。

I would recommend to create the recursion tree for example 1 and check whether you can find overlapping sub-problems. There will be a lot of overlapping problems even for smaller inputs.

我建议为示例1创建递归树,并检查是否可以找到重叠的子问题。 即使对于较小的输入,也会有很多重叠的问题。

So, we need to pass that overhead and we can solve that by memorization technique where we store the value of solved sub-problem in DP[][]

因此,我们需要传递该开销,并且可以通过存储将已解决子问题的值存储在DP [] []中的记忆技术来解决该问题。

So, we first lookup in DP[][] whether it's already solved or not. If it's already solved then we will have some value for DP[i][j] (for subproblem, f(i,j)), Else DP[i][j] will contain the initialized value only.

因此,我们首先在DP [] []中查找它是否已解决。 如果已经解决,则DP [i] [j]会有一些值(对于子问题f(i,j) ),其他DP [i] [j]仅包含初始化值。

This is the trick here.

这是这里的把戏。

Below is the full CPP implementation for understanding memorization.

以下是用于理解记忆的完整CPP实施。

C++ Implementation:

C ++实现:

#include <bits/stdc++.h>
using namespace std;
int findmax(vector<int> arr, int in, int n, int* lastindex)
{
int max = INT_MIN;
for (int i = 0; i < n; i++) {
if (arr[i] > max && i != in) {
max = arr[i];
*lastindex = i;
}
}
return max;
}
int recurZigZag(vector<vector<int> > arr, int row, int col, int n, int** dp)
{
//memoization part
if (dp[row][col] != -1) //if already solved, no need to compute again
return dp[row][col];
if (row == n - 1) {
dp[row][col] = arr[row][col];
return arr[row][col];
}
int max = INT_MIN;
for (int k = 0; k < n; k++) {
if (k != col) {
int t = recurZigZag(arr, row + 1, k, n, dp);
if (max < t)
max = t;
}
}
dp[row][col] = std::max(dp[row][col], arr[row][col] + max); //store solution
return dp[row][col];
}
int main()
{
int t, n, item;
cout << "Enter test case:\n";
cin >> t;
for (int i = 0; i < t; i++) {
cout << "Input size of square matrix\n";
cin >> n;
vector<vector<int> > arr;
cout << "Input the square matrix\n";
for (int i = 0; i < n; i++) {
vector<int> inn;
for (int j = 0; j < n; j++) {
cin >> item;
inn.push_back(item);
}
arr.push_back(inn);
}
int** dp = (int**)(malloc(sizeof(int*) * n));
for (int i = 0; i < n; i++) {
dp[i] = (int*)(malloc(sizeof(int) * n));
for (int j = 0; j < n; j++)
dp[i][j] = -1;
}
int mymax = INT_MIN;
for (int i = 0; i < n; i++) {
int p = recurZigZag(arr, 0, i, n, dp);
if (p > mymax)
mymax = p;
}
cout << "Maximum zigzag sum: " << mymax << endl;
}
return 0;
}

Output

输出量

Enter test case:
2
Input size of square matrix 
3
Input the square matrix  
3 8 2  
4 8 5  
6 9 7  
Maximum zigzag sum: 22
Input size of square matrix 
3
Input the square matrix  
3 2 1  
10 8 5 
6 6 4  
Maximum zigzag sum: 18

翻译自: https://www.includehelp.com/icp/largest-zigzag-sequence.aspx

ue 抗锯齿 渲染序列失灵

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/540653.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

团队-团队编程项目作业名称-成员简介及分工

成员&#xff1a;祁昊 分工&#xff1a;ui设计&#xff0c;美工&#xff0c;详细设计。转载于:https://www.cnblogs.com/qihao10086/p/7496101.html

python身份运算符_Python身份运算符

python身份运算符Identity operators are used to perform the comparison operation on the objects i.e. these operators check whether both operands refer to the same objects (with the same memory location) or not. 身份运算符用于对对象执行比较操作&#xff0c;即…

Oracle-Decode()函数和CASE语句的不同

Oracle-Decode()函数和CASE语句的区别&#xff1a; 具体示例如下&#xff1a; 1.CASE语句&#xff1a; SELECT CASE SIGN(5 - 5) WHEN 1 THEN Is Positive WHEN -1 THEN Is Negative ELSE Is Zero END FROM DUAL; 后台实现&#xff1a; if (SIGN(5 – 5) 1) { Is Positive; } …

ai智能模式_AI的完整形式是什么?

ai智能模式AI&#xff1a;人工智能 (AI: Artificial Intelligence) AI is an abbreviation of "artificial intelligence", which occasionally called machine intelligence in the field of computer science. It is intelligence made understandable by machines…

centos6.5安装python3.6

1、下载Python安装包 wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz 2、解压安装包&#xff1a;tar -xzvf Python-3.6.0.tgz 3、进入安装包路径&#xff1a;cd Python-3.6.04、编译安装包 注意&#xff1a;prefix参数用于指定将Python安装在新目录&#xff…

BE的完整形式是什么?

工学学士 (BE: Bachelor of Engineering) BE is an abbreviation of Bachelor of Engineering. It is a bachelors degree program for under graduation in engineering and the duration of this course is 4 years. It is provided in many countries like India, Canada, S…

史上最详细Windows版本搭建安装React Native环境配置

说在前面的话: 感谢同事金晓冰倾情奉献本环境搭建教程 之前我们已经讲解了React Native的OS X系统的环境搭建以及配置&#xff0c;鉴于各大群里有很多人反应在Windows环境搭建出现各种问题&#xff0c;今天就特意更新一贴来说明。关于os x环境搭建以及react native入门学习资料…

程序代码错误检测_错误检测代码

程序代码错误检测错误检测代码 (Error Detecting Codes) A group of bits is known as words, and these words move as an entity from one block to another in the digital system. While moving from one part to another within the system via transmission media, the b…

Web浏览器端通过https 使用mqtt通讯

做的产品简介 这次需要做一个web端的上课平台&#xff0c;有音视频通讯&#xff0c;有白板(画板)功能&#xff0c;有文字通讯等。技术点 音视频通讯需要走Webrtc需要跟ios, android, windows, mac 客户端互联互通一般通讯通过mqtt协议MQTT简介 MQTT&#xff08;Message Queuing…

vga显示模式_VGA的完整形式是什么?

vga显示模式VGA&#xff1a;视频图形阵列 (VGA: Video Graphics Array) VGA is an abbreviation of "Video Graphics Array". VGA是“视频图形阵列”的缩写 。 It is a three-row 15-pin DE-15 connector display hardware developed by IBM in 1987. It was first …

【iCore4 双核心板_FPGA】例程十一:FSMC总线通信实验——独立地址模式

实验原理&#xff1a; STM32F767上自带FMC控制器&#xff0c;本实验将通过FMC总线的地址独立模式实现STM32与FPGA 之间通信&#xff0c;FPGA内部建立RAM块,FPGA桥接STM32和RAM块&#xff0c;本实验通过FSMC总线从STM32向 RAM块中写入数据&#xff0c;然后读取RAM出来的数据进行…

世界粮农组织五大健康食品_粮农组织的完整形式是什么?

世界粮农组织五大健康食品粮农组织&#xff1a;请注意 (FAO: For the Attention Of) FAO is an abbreviation of "For the Attention Of". FAO是“ For the Attention Of”的缩写 。 It is an expression, which is commonly used in the Gmail platform. When a ma…

http 412 precondition failed

2019独角兽企业重金招聘Python工程师标准>>> 今天在谷歌浏览器上刷新页面的时候&#xff0c;出现了 如下失败信息&#xff1a; HTTP 412 (Precondition Failed) 想想当时的动作是在发送ajax请求失败之后&#xff0c;再刷新&#xff0c;就会出现上面的失败问题。百度…

Python | Pyplot标签

There are the following types of labels, 标签有以下几种&#xff0c; 1)X轴贴标 (1) X-axis labelling) plt.xlabel(Number Line)# Default labellingplt.xlabel(Number Line, colorgreen)#Font colour Changedplt.xlabel(Number Line, colorGreen, fontsize15)#Font size …

LTNS的完整形式是什么?

LTNS&#xff1a;很久没看到 (LTNS: Long Time No See) LTNS is an abbreviation of "Long time, no see". LTNS是“长时间&#xff0c;看不见”的缩写 。 It is an English phrase used when people meet and greet each other after a while when in between they…

MySQL Index Condition Pushdown

2019独角兽企业重金招聘Python工程师标准>>> 一、Index Condition Pushdown简介 ICP&#xff08;index condition pushdown&#xff09;是mysql利用索引&#xff08;二级索引&#xff09;元组和筛字段在索引中的where条件从表中提取数据记录的一种优化操作。ICP的思…

ADBB的完整形式是什么?

ADBB&#xff1a;所有完成的再见 (ADBB: All Done Bye Bye) ADBB is an abbreviation to All Done Bye Bye. ADBB是All Done Bye Bye的缩写。 Whenever a person wants to convey his message to another person, they use some sort of short-form in the text messages. ADB…

c 环境

系统ubuntu sudo apt-get install vim g openssh-server libgl1-mesa-dev检查下安装的版本gcc -v g -v make -v gdb -v 转载于:https://blog.51cto.com/skinglzw/1964449

java.util (Collection接口和Map接口)

1&#xff1a;Collection和Map接口的几个主要继承和实现类 1.1 Collection接口 Collection是最基本的集合接口&#xff0c;一个Collection代表一组Object&#xff0c;即Collection的元素&#xff08;Elements&#xff09;。一些Collection允许相同的元素而另一些不行。一些能排…

scala 拆分字符串翻转_Scala程序分割字符串

scala 拆分字符串翻转A string is a collection that stores multiple characters, it is an immutable sequence which cannot be changed. 字符串是存储多个字符的集合&#xff0c;它是不可更改的不可更改的序列。 分割字符串 (Splitting a string) In Scala, using the spl…