当前位置:网站首页>数字三角形模型 AcWing 1027. 方格取数
数字三角形模型 AcWing 1027. 方格取数
2022-07-27 10:35: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;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- Asustek unparalleled, this may be the best affordable high brush thin notebook on the screen
- 15th largest value of data flow
- 深析C语言的灵魂 -- 指针
- 学习笔记-uni-app
- The second method of calculating overlapping integral
- 博弈论 AcWing 892. 台阶-Nim游戏
- Caused by:org.gradle.api.internal.plugins . PluginApplicationException: Failed to apply plugin
- TensorFlow张量运算函数集
- 对象数组去重
- The influence of the number of non-zero values in the picture on Classification
猜你喜欢

Openatom openharmony sub forum, see you today at 14:00! Wonderful release of memorabilia attached

最长上升子序列模型 AcWing 272. 最长公共上升子序列

c语言指针函数和函数指针的辨析

博弈论 AcWing 893. 集合-Nim游戏

计算重叠积分的第二种方法

黑白像素分布对迭代次数的影响

SQL Server2000 database error

What is the mystery of the gate of the meta universe?

Compete for the key battle of stock users and help enterprises build a perfect labeling system - 01 live review

Use of beautifulsoup
随机推荐
12 is at least twice the maximum number of other numbers
Use of beautifulsoup
图片中非0值的数量对分类的影响
Learning notes uni app
背包模型 AcWing 1022. 宠物小精灵之收服
[QNX Hypervisor 2.2用户手册]9.9 logger
What changes will metauniverse bring to the music industry in the trillion market?
Wilderness search --- search iterations
最长上升子序列模型 AcWing 1012. 友好城市
The longest ascending subsequence model acwing 1017. The glider wing of the strange thief Kidd
2022牛客多校训练(3)A-Ancestor 题目翻译
荒野觅踪---寻找迭代次数
推导STO双中心动能积分的详细展开式
Application of 5g private network in smart medicine
TensorFlow张量运算函数集
博弈论 AcWing 893. 集合-Nim游戏
Object array de duplication
最长上升子序列模型 AcWing 1016. 最大上升子序列和
Research on synaesthesia integration and its challenges
A verification test of the relationship between iteration number and entropy