当前位置:网站首页>Digital triangle model acwing 1027 Grid access
Digital triangle model acwing 1027 Grid access
2022-07-07 08:51:00 【T_ Y_ F666】
Digital triangle model AcWing 1027. Take the number of squares
Original link
AcWing 1027. Take the number of squares
Algorithm tags
DP linear DP
Ideas
Wrong thinking : Go twice
Since there may be multiple solutions with the first time of travel , You can only choose one of them . But the first place you walk will be reset to 0, It is impossible to determine whether the value of the second time will be greater than the answer you have obtained when the first time is also the optimal solution and is not selected by you 





Code
#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>=b;--i)
using namespace std;
const int N = 105;
int f[2*N][N][N], a[N][N];
int aa, b, c, d;
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n=read();
while(aa=read(), b=read(), c=read(), aa||b||c){
a[aa][b]=c;
}
// Sum of row and column values The row determines the column
rep(k, 2, n+n+1){
// First time i That's ok
rep(i1, 1, n+1){
// Second time i That's ok
rep(i2, 1, n+1){
// j1 It means the first time j Column j2 It means the second time j Column
int j1=k-i1, j2=k-i2;
if(j1>=1&&j1<=n&&j2>=1&&j2<=n){
int t=a[i1][j1];
// Not the same path
if(i1-i2){
t+=a[i2][j2];
}
// Next Lower right The lower right Right, right
f[k][i1][i2]=max({f[k][i1][i2], f[k-1][i1-1][i2-1]+t, f[k-1][i1-1][i2]+t, f[k-1][i1][i2-1]+t, f[k-1][i1][i2]+t});
}
}
}
}
printf("%lld", f[2*n][n][n]);
return 0;
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support 
边栏推荐
- How to realize sliding operation component in fast application
- Pointer advanced, string function
- Greenplum 6.x common statements
- Upload an e-office V9 arbitrary file [vulnerability recurrence practice]
- Greenplum6.x-版本变化记录-常用手册
- 使用AGC重签名服务前后渠道号信息异常分析
- Nanjing commercial housing sales enabled electronic contracts, and Junzi sign assisted in the online signing and filing of housing transactions
- mysql分区讲解及操作语句
- [Yu Yue education] basic reference materials of electrical and electronic technology of Nanjing Institute of information technology
- LeetCode 736. LISP syntax parsing
猜你喜欢

数字三角形模型 AcWing 1027. 方格取数

Esp32-ulp coprocessor low power mode RTC GPIO interrupt wake up

Platformization, a fulcrum of strong chain complementing chain

ncs成都新電面試經驗

Arm GIC (IV) GIC V3 register class analysis notes.

如何在快应用中实现滑动操作组件

Analysis of using jsonp cross domain vulnerability and XSS vulnerability in honeypot

Greenplum6.x搭建_安装
![[Yugong series] February 2022 U3D full stack class 007 - production and setting skybox resources](/img/e3/3703bdace2d0ca47c1a585562dc15e.jpg)
[Yugong series] February 2022 U3D full stack class 007 - production and setting skybox resources

Appeler l'interface du moteur de création du service multimédia de jeu Huawei renvoie le Code d'erreur 1002, le message d'erreur: les paramètres sont l'erreur
随机推荐
如何在快应用中实现滑动操作组件
[南京大学]-[软件分析]课程学习笔记(一)-introduction
Appeler l'interface du moteur de création du service multimédia de jeu Huawei renvoie le Code d'erreur 1002, le message d'erreur: les paramètres sont l'erreur
調用華為遊戲多媒體服務的創建引擎接口返回錯誤碼1002,錯誤信息:the params is error
xray的简单使用
RuntimeError: Calculated padded input size per channel: (1 x 1). Kernel size: (5 x 5). Kernel size c
Compilation and linking of programs
Download and install orcale database11.2.0.4
Composer change domestic image
Calling the creation engine interface of Huawei game multimedia service returns error code 1002, error message: the params is error
数字三角形模型 AcWing 1027. 方格取数
Oracle makes it clear at one time that a field with multiple separators will be split into multiple rows, and then multiple rows and columns. Multiple separators will be split into multiple rows, and
Explain Huawei's application market in detail, and gradually reduce 32-bit package applications and strategies in 2022
POJ - 3784 running medium
JS的操作
[Chongqing Guangdong education] organic electronics (Bilingual) reference materials of Nanjing University of Posts and Telecommunications
Speaking of a software entrepreneurship project, is there anyone willing to invest?
Why choose cloud native database
Gson converts the entity class to JSON times declare multiple JSON fields named
Rapid integration of authentication services - harmonyos platform