当前位置:网站首页>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 
边栏推荐
- 年薪50w阿裏P8親自下場,教你如何從測試進階
- Greenplum6.x搭建_环境配置
- Qt Charts使用(重写QChartView,实现一些自定义功能)
- All about PDF crack, a complete solution to meet all your PDF needs
- Find the original code, inverse code and complement of signed numbers [C language]
- JS operation
- 对API接口或H5接口做签名认证
- National SMS center number inquiry
- Data analysis methodology and previous experience summary 2 [notes dry goods]
- Golan idea IntelliJ cannot input Chinese characters
猜你喜欢

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

A bug using module project in idea

详解华为应用市场2022年逐步减少32位包体上架应用和策略

Mountaineering team (DFS)

AVL balanced binary search tree

登山小分队(dfs)

调用华为游戏多媒体服务的创建引擎接口返回错误码1002,错误信息:the params is error

为不同类型设备构建应用的三大更新 | 2022 I/O 重点回顾

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

IP地址的类别
随机推荐
LeetCode 736. LISP syntax parsing
Enterprise manager cannot connect to the database instance
IP地址的类别
Input and output of floating point data (C language)
MAC OSX php dyld: Library not loaded: /usr/local/xxxx. dylib
Mountaineering team (DFS)
指针进阶,字符串函数
JS operation
详解华为应用市场2022年逐步减少32位包体上架应用和策略
Routing information protocol rip
Rapid integration of authentication services - harmonyos platform
数据库存储---表分区
[machine learning] watermelon book data set_ data sharing
Un salaire annuel de 50 W Ali P8 vous montrera comment passer du test
[Nanjing University] - [software analysis] course learning notes (I) -introduction
uniapp 微信小程序监测网络
Lenovo hybrid cloud Lenovo xcloud: 4 major product lines +it service portal
About using CDN based on Kangle and EP panel
阿里p8推荐,测试覆盖率工具—Jacoco,实用性极佳
9c09730c0eea36d495c3ff6efe3708d8