当前位置:网站首页>Minimum toll
Minimum toll
2022-06-10 00:43:00 【Wuhu boy】
Title Description
A businessman walked through a N × N N×N N×N A grid of squares , Go to a very important business activity .
He wants to enter from the upper left corner of the grid , Lower right corner out .
Every time you cross the middle 1 A small square , All costs. 1 Unit time .
Businessmen must be in ( 2 N − 1 ) (2N−1) (2N−1) A unit of time goes through .
And when passing through each small square in the middle , All need to pay a certain fee .
The merchant expects to cross out with the least cost within the specified time .
How much does it cost at least ?
Be careful : You can't cross small squares diagonally ( namely , It can only move up, down, left and right, and cannot leave the grid ).
Input format
The first line is an integer , Represents the width of the square N N N.
Back N N N That's ok , Each row N N N No more than one. 100 The positive integer , For the cost of each small square on the grid .
Output format
Output an integer , Indicates the minimum cost required .
Data range
1 ≤ N ≤ 100 1≤N≤100 1≤N≤100
Examples
sample input
5
1 4 6 8 10
2 5 7 15 17
6 8 9 18 20
10 11 12 19 21
20 23 25 29 33
sample output
109
Sample explanation
In the example , The minimum value is 109=1+2+5+7+9+12+19+21+33.
Ideas
This question is similar to the number triangle type , But it's a little different , Is to seek most Small value \color{Red}{ minimum value } most Small value , Therefore, it is necessary to consider the initialization state and the judgment of out of bounds during state transition 
C++ Code
#include <iostream>
#include <cstring>
using namespace std;
const int N = 110, INF = 1e9;
int a[N][N], f[N][N];
int n;
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= n; j ++)
scanf("%d", &a[i][j]);
// Initialize to positive infinity
memset(f,0x3f,sizeof f);
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= n; j ++)
{
if (i == 1 && j == 1) f[i][j] = a[i][j];
else f[i][j] = min(f[i - 1][j], f[i][j - 1]) + a[i][j];
}
printf("%d", f[n][n]);
return 0;
}
边栏推荐
- [docker]mysql scheduled backup
- The original code, inverse code, complement code and shift code are finally understood
- 二叉树展开为链表[树处理的精髓--如何处理每一颗子树]
- MySQL execution plan
- run npm fund for details
- 嵌入式商业智能软件Wyn Enterprise正式步入V5.0时代!
- 最低通行费
- flutter pub get failed (66; Could not find a file named “pubspec.yaml“
- pycharm 2022永久激活版下载,亲测有效
- Mind map - 3. SQL injection vulnerability
猜你喜欢

Ups and downs of network status

SIGIR 2022 | HKU and Wuhan University put forward kgcl: a recommendation system based on knowledge map comparative learning

1049大盗阿福

ECA-Net: Efficient Channel Attention for Deep Convolutional Neural Networks
Blue Bridge Cup · winter vacation hundred schools' real topic league tournament (Phase V) real topic exercise of cargo placement for graduate students and university group A

最低通行费

ECA-Net: Efficient Channel Attention for Deep Convolutional Neural Networks

MySQL execution plan

Enterprise worry free | apipost privatization deployment activity is about to start
试题 历届真题 成绩分析【第十一届】【省赛】【B组】
随机推荐
[vscode] the problem that the vscode SFTP plug-in cannot be used after upgrading to version 1.59
wps合并单元格快捷键是什么
Go zero micro Service Practice Series (II. Service splitting)
Ups and downs of network status
FlinkSQL 之乱序问题
修复win10的微软应用商店闪退
最低通行费
732. my schedule III
Flutter ITMS-90338: Non-public API usage - Frameworks/webview_flutter_wkwebview.framework
typora 基本使用和更换typora的主题样式
Application of technical scheme of PTP time server (NTP network time server)
Transformer
Go Technology Daily (June 8, 2022) -- talk about 10 scenarios of index failure. It's too stupid
Collection backup | summary of some common problems about oauth2
Go profile management -viper
界面控件DevExpress WinForms——全新的WXI皮肤抢“鲜”看
Answers to engineering ethics after class exercises
Do you know about singleton mode? I don't understand anyway.
Py6s configuration tutorial (win10 × 64)
Is Huishang futures regular? Is it safe to open an account?