当前位置:网站首页>数字三角形模型 AcWing 1018. 最低通行费
数字三角形模型 AcWing 1018. 最低通行费
2022-07-06 12:15:00 【T_Y_F666】
数字三角形模型 AcWing 1018. 最低通行费
原题链接
算法标签
DP 线性DP
思路
由题意,花费时间应小于(2N−1) , 故不能走回头路, 类似于摘花生问题。
代码
#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, INF = 0x3f3f3f3f;
int f[N][N], a[N][N];
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();
rep(i, 1, n+1){
rep(j, 1, n+1){
a[i][j]=read();
}
}
rep(i, 1, n+1){
rep(j, 1, n+1){
if(i==1&&j==1){
f[i][j]=a[i][j];
}else{
f[i][j]=INF;
if(i>1){
f[i][j]=min(f[i][j], f[i-1][j]+a[i][j]);
}
if(j>1){
f[i][j]=min(f[i][j], f[i][j-1]+a[i][j]);
}
}
}
}
printf("%lld", f[n][n]);
return 0;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- Poj1149 pigs [maximum flow]
- Test Li hi
- 信息系统项目管理师---第八章 项目质量管理
- 夏志刚介绍
- Classic 100 questions of algorithm interview, the latest career planning of Android programmers
- Linear distance between two points of cesium
- logstash高速入口
- 语音识别(ASR)论文优选:全球最大的中英混合开源数据TALCS: An Open-Source Mandarin-English Code-Switching Corpus and a Speech
- [infrastructure] deployment and configuration of Flink / Flink CDC (MySQL / es)
- Learning and Exploration - function anti shake
猜你喜欢

rt-thread i2c 使用教程
![[play with Linux] [docker] MySQL installation and configuration](/img/04/6253ef9fdf7d2242b42b4c7fb2c607.png)
[play with Linux] [docker] MySQL installation and configuration

Information System Project Manager - Chapter VIII project quality management

PowerPivot——DAX(初识)

Learn to explore - use pseudo elements to clear the high collapse caused by floating elements
腾讯架构师首发,2022Android面试笔试总结

Learning and Exploration - Seamless rotation map
腾讯安卓开发面试,android开发的基础知识

Social recruitment interview experience, 2022 latest Android high-frequency selected interview questions sharing

理解 YOLOV1 第二篇 预测阶段 非极大值抑制(NMS)
随机推荐
Speech recognition (ASR) paper selection: talcs: an open source Mandarin English code switching corps and a speech
深度剖析原理,看完这一篇就够了
Test Li hi
VMware virtual machine cannot open the kernel device "\.\global\vmx86"
Blue Bridge Cup microbial proliferation C language
某东短信登录复活 安装部署教程
Vscode debug run fluent message: there is no extension for debugging yaml. Should we find yaml extensions in the market?
Crawler (14) - scrape redis distributed crawler (1) | detailed explanation
技术分享 | 抓包分析 TCP 协议
Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
[network planning] Chapter 3 data link layer (3) channel division medium access control
Cesium Click to draw a circle (dynamically draw a circle)
A5000 vgpu display mode switching
使用ssh连接被拒
Tencent T2 Daniel explained in person and doubled his job hopping salary
Hudi vs Delta vs Iceberg
HDU 1026 Ignatius and the Princess I 迷宫范围内的搜索剪枝问题
Node. Js: express + MySQL realizes registration, login and identity authentication
Cesium 两点之间的直线距离
Tencent Android development interview, basic knowledge of Android Development