Blue Bridge Cup-pass note (dual thread DP)

Source: Internet
Author: User


Topic Transfer: Pass the note


IDEA: Double thread DP, specific look at the code;


AC Code:

#include <map> #include <set> #include <cmath> #include <deque> #include <queue> #include <stack> #include <cstdio> #include <cctype> #include <string> #include <vector> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> #define LL long long# Define INF 0x7fffffffusing namespace Std;int N, m;int a[55][55];int dp[105][55][55];//dp[k][i][j] Represents the maximum value of the number of I and J numbers that can go to the K-slash, int main () {scanf ("%d%d", &n, &m), for (int i = 0; I <= n + 1; i + +) {//assignment-independent values are negative infinity for (i NT J = 0; J <= m + 1; J + +) {A[i][j] =-inf;}} for (int i = 1; I <= n; i + +) {for (int j = 1; j <= M; j + +) {scanf ("%d", &a[i][j]);}} int len = (n + m-1), for (int k = 2; k <= Len, K + +) {for (int i = 1; i < K; i + +) {for (int j = i + 1; j <= K; j + +) {Dp[k][i][j] = A[k-i+1][i] + a[k-j+1][j] + max (max (dp[k-1][i-1][j-1], dp[k-1][i-1][j]), Max (Dp[k-1][i][j-1], dp[k-1][ I][J]));}}} printf ("%d\n", Dp[len-1][m-1][m]); return 0;}











Blue Bridge Cup-pass note (dual thread DP)

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.