当前位置:网站首页>[dynamic programming] p1004 grid access (four-dimensional DP template question)
[dynamic programming] p1004 grid access (four-dimensional DP template question)
2022-07-01 14:21:00 【muse_ age】

The same method as passing a note !
use f[i][j][k][l] The first person to come to (i,j), The second man came to (k,l) The best solution
We consider the Two people go at the same time , Equivalent to Digital triangle .
The equation of state transfer is :
f[i][j][k][l]=max(f[i-1][j][k-1][l],f[i-1][j][k][l-1],f[i][j-1][k-1][l],f[i][j-1][k][l-1])+a[i][j]+a[k][l];f[i][j][k][l]=max(f[i−1][j][k−1][l],f[i−1][j][k][l−1],f[i][j−1][k−1][l],f[i][j−1][k][l−1])+a[i][j]+a[k][l];
Because it can only be taken once , So when two people meet , Only add once , Otherwise, add two times (0 No impact )
The two met :i==k&&j==l
Code :
#include<iostream>
using namespace std;
int n;
int a,b,c;
int G[100][100];
int dp[100][100][100][100];
void output(){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cout<<G[i][j]<<" ";
}
cout<<endl;
}
}
int main(){
cin>>n;
cin>>a>>b>>c;
while(!(a==0&&b==0&&c==0)){
G[a][b]=c;
cin>>a>>b>>c;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
for(int k=1;k<=n;k++){
for(int l=1;l<=n;l++){
dp[i][j][k][l]=max(max(dp[i-1][j][k-1][l],dp[i][j-1][k-1][l]),max(dp[i-1][j][k][l-1],dp[i][j-1][k][l-1]))+G[i][j]+G[k][l]*(i!=k&&j!=l);
}
}
}
}
cout<<dp[n][n][n][n];
}边栏推荐
- C 语言基础
- WebSocket(简单体验版)
- Research Report on the development trend and competitive strategy of the global aviation leasing service industry
- When the main process architecture game, to prevent calls everywhere to reduce coupling, how to open the interface to others to call?
- 户外LED显示屏应该考虑哪些问题?
- Basic concepts of programming
- App automation testing Kaiyuan platform appium runner
- Research Report on the development trend and competitive strategy of the global pipeline robot inspection camera industry
- Research Report on the development trend and competitive strategy of the global axis measurement system industry
- Scheme of printing statistical information in log
猜你喜欢

算网融合赋能行业转型,移动云点亮数智未来新路标

Use the right scene, get twice the result with half the effort! Full introduction to the window query function and usage scenarios of tdengine

This paper introduces an implementation scheme to enhance the favorite transaction code management tool in SAP GUI

Fundamentals of C language

leetcode622.设计循环队列(C语言)

Leetcode(69)——x 的平方根

C 语言基础

Use lambda function URL + cloudfront to realize S3 image back to source

数据湖系列之一 | 你一定爱读的极简数据平台史,从数据仓库、数据湖到湖仓一体

使用net core 6 c# 的 NPOI 包,读取excel..xlsx单元格内的图片,并存储到指定服务器
随机推荐
Is the futures company found on Baidu safe? How do futures companies determine the regularity
被裁三個月,面試到處碰壁,心態已經開始崩了
MySQL日志
Research Report on the development trend and competitive strategy of the global camera filter bracket industry
Logic is a good thing
【商业终端仿真解决方案】上海道宁为您带来Georgia介绍、试用、教程
Oracle-数据库对象的使用
sqlilabs less13
The integration of computing and Internet enables the transformation of the industry, and the mobile cloud lights up a new roadmap for the future of digital intelligence
如何看待国企纷纷卸载微软Office改用金山WPS?
Research Report on the development trend and competitive strategy of the global commercial glassware industry
This paper introduces an implementation scheme to enhance the favorite transaction code management tool in SAP GUI
C 语言基础
Use of Oracle database objects
Research Report on the development trend and competitive strategy of the global indexable milling cutter industry
Leetcode(69)——x 的平方根
phpcms实现订单直接支付宝支付功能
使用net core 6 c# 的 NPOI 包,读取excel..xlsx单元格内的图片,并存储到指定服务器
玩转MongoDB—搭建MongoDB集群
Research Report on the development trend and competitive strategy of the global CCTV robot industry