当前位置:网站首页>7-3 minimum toll
7-3 minimum toll
2022-06-26 13:21:00 【White -】
7-3 Minimum tolls
A businessman walked through a 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 (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.
Back N That's ok , Each row 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
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.
Code :
#include<iostream>
using namespace std;
int main()
{
int n,i,j,a[102][102];
cin>>n;
for (i=0;i<102;i++)
for (j=0;j<102;j++)
a[i][j]=9990;
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
cin>>a[i][j];
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
{
if (i==1&&j==1)
continue;
else
{
if (a[i][j]+a[i][j-1]>a[i][j]+a[i-1][j])
a[i][j]=a[i][j]+a[i-1][j];
if(a[i][j]+a[i][j-1]<=a[i][j]+a[i-1][j])
a[i][j]=a[i][j]+a[i][j-1];
}
}
cout<<a[n][n]<<endl;
return 0;
}
202206260904 Japan
边栏推荐
- 首批通过!百度智能云曦灵平台获信通院数字人能力评测权威认证
- What should the software test report include? Interview must ask
- Beifu cx5130 card replacement and transfer of existing authorization files
- Do you know the limitations of automated testing?
- 【Spark】. Explanation of several icons of scala file in idea
- 偶言佳句,孤芳自赏
- ES6 module
- What features are added to Photoshop 2022 23.4.1? Do you know anything
- G - Cow Bowling
- Common creation and usage of singletons
猜你喜欢

Do you know the limitations of automated testing?

shell脚本详细介绍(四)

Prototype

【Spark】. Explanation of several icons of scala file in idea
![[how to connect the network] Chapter 2 (Part 1): establish a connection, transmit data, and disconnect](/img/e3/a666ba2f48e8edcc7db80503a6156d.png)
[how to connect the network] Chapter 2 (Part 1): establish a connection, transmit data, and disconnect

Script - crawl the customized storage path of the cartoon and download it to the local

To solve the difficulties of small and medium-sized enterprises, Baidu AI Cloud makes an example

Arcpy - - utilisation de la fonction insertlayer (): ajout de calques dans un document de carte

首批通过!百度智能云曦灵平台获信通院数字人能力评测权威认证

Echart stack histogram: add white spacing effect setting between color blocks
随机推荐
Processing polyhedron change
KITTI Tracking dataset whose format is letf_ top_ right_ bottom to JDE normalied xc_ yc_ w_ h
Echart stack histogram: add white spacing effect setting between color blocks
8. [STM32] timer (TIM) -- interrupt, PWM, input capture experiment (proficient in timer)
sed编辑器
tauri vs electron
First pass! Baidu AI Cloud Xiling platform has obtained the authoritative certification of digital human ability evaluation from the Institute of information technology
Summary of wechat applet test points
Common faults of MySQL database - forgetting database password
Here Document免交互及Expect自动化交互
C - Common Subsequence
Beifu PLC realizes zero point power-off hold of absolute value encoder -- use of bias
Custom encapsulation drop-down component
Zoomeeper sets ACL permission control (only specific IP access is allowed to enhance security)
I - Dollar Dayz
外观模式(Facade)
J - Wooden Sticks poj 1065
I have a good word to say, and I admire myself
Word document export (using fixed template)
Electron official docs series: Development