当前位置:网站首页>数字三角形模型 AcWing 1027. 方格取数
数字三角形模型 AcWing 1027. 方格取数
2022-07-07 06:11:00 【T_Y_F666】
数字三角形模型 AcWing 1027. 方格取数
原题链接
算法标签
DP 线性DP
思路
错误思路:分两次走
由于第一次走时可能存在多条路径都是第一次的解集,分开走只能选择其中的一条。但第一次走过的地方会被重置成0,无法确定是第一次同样是最优解而未被你选择的情况下第二次的值会不会比你已经得出的答案要大





代码
#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;
}
// 行列值之和 由行确定列
rep(k, 2, n+n+1){
// 第一次第i行
rep(i1, 1, n+1){
// 第二次第i行
rep(i2, 1, n+1){
// j1表示第一次第j列 j2表示第二次第j列
int j1=k-i1, j2=k-i2;
if(j1>=1&&j1<=n&&j2>=1&&j2<=n){
int t=a[i1][j1];
// 非同一条路径
if(i1-i2){
t+=a[i2][j2];
}
// 下下 下右 右下 右右
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;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- Rapid integration of authentication services - harmonyos platform
- [Chongqing Guangdong education] organic electronics (Bilingual) reference materials of Nanjing University of Posts and Telecommunications
- Several ways of lambda used in functions in kotlin (higher-order functions)
- Greenplum 6.x version change record common manual
- Database storage - table partition
- PLSQL的安装和配置
- [Chongqing Guangdong education] accounting reference materials of Nanjing University of Information Engineering
- JS operation
- How to understand distributed architecture and micro service architecture
- JS的操作
猜你喜欢

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

National standard gb28181 protocol video platform easygbs adds streaming timeout configuration

調用華為遊戲多媒體服務的創建引擎接口返回錯誤碼1002,錯誤信息:the params is error

Virtual address space

MySQL introduction - crud Foundation (establishment of the prototype of the idea of adding, deleting, changing and searching)

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

Why choose cloud native database

Installation and configuration of PLSQL

Greenplum 6.x common statements

Componentspace2022, assertions, protocols, bindings, and configuration files
随机推荐
【踩坑】nacos注册一直连接localhost:8848,no available server
如何在图片的目标中添加目标的mask
NCS Chengdu Xindian interview experience
Golan idea IntelliJ cannot input Chinese characters
Other 7 features of TCP [sliding window mechanism ▲]
快速集成认证服务-HarmonyOS平台
How to realize the high temperature alarm of the machine room in the moving ring monitoring system
Gson converts the entity class to JSON times declare multiple JSON fields named
opencv 将16位图像数据转为8位、8转16
JS的操作
Data type - integer (C language)
let const
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
Qt Charts使用(重写QChartView,实现一些自定义功能)
【微信小程序:缓存操作】
Are you holding back on the publicity of the salary system for it posts such as testing, development, operation and maintenance?
[kuangbin]专题十五 数位DP
Input and output of floating point data (C language)
Greenplum6.x监控软件搭建
关于基于kangle和EP面板使用CDN