当前位置:网站首页>[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];
}边栏推荐
- Fiori applications are shared through the enhancement of adaptation project
- Research Report on development trend and competitive strategy of global vibration polishing machine industry
- Research Report on the development trend and competitive strategy of the global CCTV robot industry
- How to pass array parameters in get request
- sqlilabs less-11~12
- 数据湖系列之一 | 你一定爱读的极简数据平台史,从数据仓库、数据湖到湖仓一体
- 被裁三個月,面試到處碰壁,心態已經開始崩了
- sqlilabs less13
- 玩转MongoDB—搭建MongoDB集群
- sqlilabs less10
猜你喜欢

2022-2-15 learning xiangniuke project - Section 1 filtering sensitive words

深度合作 | 涛思数据携手长虹佳华为中国区客户提供 TDengine 强大企业级产品与完善服务保障

户外LED显示屏应该考虑哪些问题?

Websocket (simple experience version)

Animesr: learnable degradation operator and new real world animation VSR dataset

leetcode622. Design cycle queue (C language)

WebSocket(简单体验版)

How will the surging tide of digitalization overturn the future?

原来程序员搞私活这么赚钱?真的太香了

TDengine 连接器上线 Google Data Studio 应用商店
随机推荐
当主程架构游戏的时候,防止到处调用减少耦合性,怎么开放接口给其他人调用呢?
C语言课程设计题目
8 best practices to protect your IAC security!
【IoT毕设.上】STM32+机智云AIoT+实验室安全监控系统
用栈实现队列、用队列实现栈(C语言_leetcode_232+225)
Research Report on development trend and competitive strategy of global 4-aminodiphenylamine industry
[IOT completion. Part 2] stm32+ smart cloud aiot+ laboratory security monitoring system
自定义注解实现验证信息的功能
【NLP】预训练模型——GPT1
SQLAchemy 常用操作
WebSocket(简单体验版)
Research Report on development trend and competitive strategy of global vibration polishing machine industry
Use the right scene, get twice the result with half the effort! Full introduction to the window query function and usage scenarios of tdengine
Go整合Logrus实现日志打印
2022 PMP project management examination agile knowledge points (6)
sqlilabs less13
那个很努力的学生,高考失败了……别慌!你还有一次逆袭机会!
QT community management system
Basis of target detection (NMS)
2022. Let me take you from getting started to mastering jetpack architecture components - lifecycle