当前位置:网站首页>数字三角形模型 AcWing 1018. 最低通行费
数字三角形模型 AcWing 1018. 最低通行费
2022-07-27 10:35: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;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- Shortest moving distance and entropy of morphological complex
- Redis+caffeine two-level cache enables smooth access speed
- 荒野觅踪---寻找迭代次数
- 最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼
- A verification test of the relationship between iteration number and entropy
- 背包模型 AcWing 1024. 装箱问题
- Non progressive phenomena of entropy and morphology
- 12 is at least twice the maximum number of other numbers
- SQL Server2000 database error
- MySQL installation (RPM package)
猜你喜欢

Instructions for mock platform

JVM judges that the object is dead, and practices verify GC recycling

Derive the detailed expansion of STO double center kinetic energy integral

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

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

背包模型 AcWing 423. 采药

Opengauss kernel analysis - statistics and row count estimation

NFT leaderboard -nft real offer latest address: NFT leaderboard.com

The difference of iteration number and information entropy

MySQL installation (RPM package)
随机推荐
Analysis of C language pointer function and function pointer
XXX packages are looking for funding run 'NPM fund' for details solutions
中国剩余定理 AcWing 204. 表达整数的奇怪方式
区间问题 AcWing 906. 区间分组
Longest ascending subsequence model acwing 1012. Sister Cities
[FPGA tutorial case 40] communication case 10 -- Verilog implementation of a simple OFDM system based on FPGA
Non progressive phenomena of entropy and morphology
Learning notes uni app
最短移动距离和形态复合体的熵
How to build a real-time development platform to deeply release the value of enterprise real-time data?
深析C语言的灵魂 -- 指针
Application of 5g private network in smart medicine
最长上升子序列模型 AcWing 1016. 最大上升子序列和
洛谷 P3052 [USACO12MAR]Cows in a Skyscraper G
最长上升子序列模型 AcWing 1012. 友好城市
The article will not keep VIP charges all the time. It will be open for a period of time
树形数据转换
Data assets are king. How to analyze the relationship between enterprise digital transformation and data asset management?
6 find the smallest letter larger than the target letter
Internal and external troubles of digital collection NFT "boring ape" bayc