当前位置:网站首页>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 
边栏推荐
- How to create a.Net image with diagnostic tools
- Tree data conversion
- Wilderness search --- search iterations
- tensorflow运行报错解决方法
- The longest ascending subsequence model acwing 1017. The glider wing of the strange thief Kidd
- Today's code farmer girl summarized her notes about NPM package management and URL module
- Use of parsel
- [FPGA tutorial case 40] communication case 10 -- Verilog implementation of a simple OFDM system based on FPGA
- Study notes Minio
- Data assets are king. How to analyze the relationship between enterprise digital transformation and data asset management?
猜你喜欢

背包模型 AcWing 1022. 宠物小精灵之收服

Budweiser, a well-known beer, plans to launch NFT in an attempt to unveil the "long planned" uplink?

Cancer DDD

Find the combination number acwing 888. find the combination number IV

解决 ImportError: cannot import name 'abs' 导入tensorflow报错

Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?

博弈论 AcWing 891. Nim游戏

Play with the cluster configuration center and learn about the Taier console

背包模型 AcWing 1024. 装箱问题

数字三角形模型 AcWing 1015. 摘花生
随机推荐
博弈论 AcWing 891. Nim游戏
Pat (Grade B) 2022 summer exam
求组合数 AcWing 886. 求组合数 II
How to build a data index system is the most effective. From 0 to 1, we will take you a quick start - 02 live review
IO stream_ Overview and explanation of data input and output flow
9 UAV array
349两个数组的交集和01两数之和
What is the mystery of the gate of the meta universe?
State compression DP acwing 91. shortest Hamilton path
求组合数 AcWing 887. 求组合数 III
Cancer DDD
Digital triangle model acwing 275. pass note
博弈论 AcWing 894. 拆分-Nim游戏
Neural network learning notes
Redis+caffeine two-level cache enables smooth access speed
洛谷P1896 互不侵犯
最长上升子序列模型 AcWing 1014. 登山
背包问题 AcWing 9. 分组背包问题
区间问题 AcWing 906. 区间分组
Learning notes - simple server implementation