当前位置:网站首页>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
边栏推荐
- 深度学习分类网络 -- ZFNet
- RT-Thread 组件 FinSH 使用时遇到的问题
- Information System Project Manager - Chapter VIII project quality management
- Microservice architecture debate between radical technologists vs Project conservatives
- leetcode先刷_Maximum Subarray
- OceanBase社区版之OBD方式部署方式单机安装
- Problems encountered in using RT thread component fish
- Speech recognition (ASR) paper selection: talcs: an open source Mandarin English code switching corps and a speech
- 转让malloc()该功能后,发生了什么事内核?附malloc()和free()实现源
- Leetcode brush first_ Maximum Subarray
猜你喜欢
It's enough to read this article to analyze the principle in depth
BUUCTF---Reverse---easyre
Tencent Android interview must ask, 10 years of Android development experience
腾讯T2大牛亲自讲解,跳槽薪资翻倍
Enumeration gets values based on parameters
PowerPivot——DAX(初识)
Pay attention to the partners on the recruitment website of fishing! The monitoring system may have set you as "high risk of leaving"
【计网】第三章 数据链路层(3)信道划分介质访问控制
Standardized QCI characteristics
持续测试(CT)实战经验分享
随机推荐
Tencent byte Alibaba Xiaomi jd.com offer got a soft hand, and the teacher said it was great
JVM_ Common [interview questions]
5. 无线体内纳米网:十大“可行吗?”问题
Logstash expressway entrance
腾讯T3大牛手把手教你,大厂内部资料
HDU 1026 Ignatius and the Princess I 迷宫范围内的搜索剪枝问题
数字三角形模型 AcWing 1018. 最低通行费
爬虫(14) - Scrapy-Redis分布式爬虫(1) | 详解
Problems encountered in using RT thread component fish
Alibaba数据源Druid可视化监控配置
Tencent Android development interview, basic knowledge of Android Development
PowerPivot——DAX(初识)
rt-thread i2c 使用教程
爬虫(14) - Scrapy-Redis分布式爬虫(1) | 详解
5. Nano - Net in wireless body: Top 10 "is it possible?" Questions
腾讯T3手把手教你,真的太香了
Crawler (14) - scrape redis distributed crawler (1) | detailed explanation
[cloud lesson] EI lesson 47 Mrs offline data analysis - processing OBS data through Flink
AsyncHandler
beegfs高可用模式探讨