当前位置:网站首页>Digital triangle model acwing 1018 Minimum toll
Digital triangle model acwing 1018 Minimum toll
2022-07-06 20:08:00 【T_ Y_ F666】
Digital triangle model AcWing 1018. Minimum tolls
Original link
Algorithm tags
DP linear DP
Ideas
From the meaning of the title , Time spent should be less than (2N−1) , So you can't go back , Similar to the problem of picking peanuts .
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, 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;
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support
边栏推荐
- 5. Wireless in vivo nano network: top ten "feasible?" problem
- Example of applying fonts to flutter
- HDU 1026 search pruning problem within the labyrinth of Ignatius and the prince I
- 永磁同步电机转子位置估算专题 —— 基波模型与转子位置角
- Case ① | host security construction: best practice of 3 levels and 11 capabilities
- 颜色(color)转换为三刺激值(r/g/b)(干股)
- Cesium 两点之间的直线距离
- Wonderful coding [hexadecimal conversion]
- 爬虫(14) - Scrapy-Redis分布式爬虫(1) | 详解
- After solving 2961 user feedback, I made such a change
猜你喜欢
Understand yolov1 Part II non maximum suppression (NMS) in prediction stage
腾讯字节阿里小米京东大厂Offer拿到手软,老师讲的真棒
【计网】第三章 数据链路层(3)信道划分介质访问控制
Tencent T3 teaches you hand in hand. It's really delicious
(3) Web security | penetration testing | basic knowledge of network security construction, IIS website construction, EXE backdoor generation tool quasar, basic use of
Tencent T3 Daniel will teach you hand-in-hand, the internal information of the factory
Tencent architects first, 2022 Android interview written examination summary
枚举根据参数获取值
2022年6月语音合成(TTS)和语音识别(ASR)论文月报
[network planning] Chapter 3 data link layer (4) LAN, Ethernet, WLAN, VLAN
随机推荐
Cesium 点击绘制圆形(动态绘制圆形)
Is it difficult for small and micro enterprises to make accounts? Smart accounting gadget quick to use
腾讯字节阿里小米京东大厂Offer拿到手软,老师讲的真棒
Case ① | host security construction: best practice of 3 levels and 11 capabilities
夏志刚介绍
Introduction to enterprise lean management system
Alibaba data source Druid visual monitoring configuration
(3) Web security | penetration testing | basic knowledge of network security construction, IIS website construction, EXE backdoor generation tool quasar, basic use of
【Yann LeCun点赞B站UP主使用Minecraft制作的红石神经网络】
Li Kou 101: symmetric binary tree
beegfs高可用模式探讨
SSH connection denied
Poj1149 pigs [maximum flow]
Leetcode 30. Concatenate substrings of all words
Period compression filter
新一代垃圾回收器—ZGC
Example of applying fonts to flutter
22-07-05 upload of qiniu cloud storage pictures and user avatars
深入浅出,面试突击版
Anaconda安装后Jupyter launch 没反应&网页打开运行没执行