当前位置:网站首页>Digital triangle model acwing 1018. Minimum toll
Digital triangle model acwing 1018. Minimum toll
2022-07-27 11:19: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 
边栏推荐
- 6 find the smallest letter larger than the target letter
- Pat (Grade B) 2022 summer exam
- Cancer DDD
- Use of pyquery
- Taishan Office Technology Lecture: scaling and opening files
- Miscellaneous records of Finance
- Data assets are king. How to analyze the relationship between enterprise digital transformation and data asset management?
- 2022牛客多校 (3)J.Journey
- What is the issuing price of NFT (Interpretation of NFT and establishment of NFT world outlook)
- Caused by:org.gradle.api.internal.plugins . PluginApplicationException: Failed to apply plugin
猜你喜欢

高斯消元 AcWing 883. 高斯消元解线性方程组

Longest ascending subsequence model acwing 1012. Sister Cities

Analysis of C language pointer function and function pointer

数字三角形模型 AcWing 1018. 最低通行费

Yonbuilder enables innovation, and the "golden keyboard Award" of the fourth UFIDA developer competition is open!

Use of parsel

数字三角形模型 AcWing 275. 传纸条

49字母异位分组和242有效的字母异位词

Game theory acwing 894. Split Nim game

Wilderness search --- search iterations
随机推荐
中国剩余定理 AcWing 204. 表达整数的奇怪方式
How to assemble a registry
博弈论 AcWing 892. 台阶-Nim游戏
洛谷P1896 互不侵犯
Yum source installation
11 wrong set
A deep analysis of the soul of C language -- pointer
Game theory acwing 894. Split Nim game
Description and feelings
洛谷P1441 砝码称重
Shortest moving distance and entropy of morphological complex
最长上升子序列模型 AcWing 1012. 友好城市
State compression DP acwing 91. shortest Hamilton path
A verification test of the relationship between iteration number and entropy
最长上升子序列模型 AcWing 272. 最长公共上升子序列
Solutions to errors in tensorflow operation
Ansible
PAT(乙级)2022年夏季考试
Knapsack model acwing 1024. Packing problem
最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼