当前位置:网站首页>数字三角形模型 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;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- String长度限制?
- 部门树递归实现
- Understand yolov1 Part II non maximum suppression (NMS) in prediction stage
- Node. Js: express + MySQL realizes registration, login and identity authentication
- [Yann Lecun likes the red stone neural network made by minecraft]
- Tencent T2 Daniel explained in person and doubled his job hopping salary
- BUUCTF---Reverse---easyre
- Tencent Android development interview, basic knowledge of Android Development
- Learn to explore - use pseudo elements to clear the high collapse caused by floating elements
- A5000 vGPU显示模式切换
猜你喜欢

企业精益管理体系介绍

《数字经济全景白皮书》保险数字化篇 重磅发布

腾讯Android面试必问,10年Android开发经验

Hudi vs Delta vs Iceberg

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

A5000 vGPU显示模式切换
![[network planning] Chapter 3 data link layer (4) LAN, Ethernet, WLAN, VLAN](/img/b8/3d48e185bb6eafcdd49889f0a90657.png)
[network planning] Chapter 3 data link layer (4) LAN, Ethernet, WLAN, VLAN

Introduction to enterprise lean management system

Configuration and simple usage of the EXE backdoor generation tool quasar

案例 ①|主机安全建设:3个层级,11大能力的最佳实践
随机推荐
[Yann Lecun likes the red stone neural network made by minecraft]
From spark csc. csr_ Matrix generate adjacency matrix
Li Kou 101: symmetric binary tree
5. 无线体内纳米网:十大“可行吗?”问题
Chic Lang: attributeerror: partially initialized module 'CV2' has no attribute 'GAPI_ wip_ gst_ GStreamerPipe
PowerPivot——DAX(初识)
Cesium Click to draw a circle (dynamically draw a circle)
Test Li hi
Crawler (14) - scrape redis distributed crawler (1) | detailed explanation
【GET-4】
Speech recognition (ASR) paper selection: talcs: an open source Mandarin English code switching corps and a speech
微信小程序常用集合
新一代垃圾回收器—ZGC
夏志刚介绍
部门树递归实现
BUUCTF---Reverse---easyre
颜色(color)转换为三刺激值(r/g/b)(干股)
Learn to explore - use pseudo elements to clear the high collapse caused by floating elements
js获取浏览器系统语言
POJ3617 Best Cow Line 馋