当前位置:网站首页>7-3 最低通行费
7-3 最低通行费
2022-06-26 12:32:00 【白—】
7-3 最低通行费
一个商人穿过一个 N×N 的正方形的网格,去参加一个非常重要的商务活动。
他要从网格的左上角进,右下角出。
每穿越中间 1 个小方格,都要花费 1 个单位时间。
商人必须在 (2N−1) 个单位时间穿越出去。
而在经过中间的每个小方格时,都需要缴纳一定的费用。
这个商人期望在规定时间内用最少费用穿越出去。
请问至少需要多少费用?
注意:不能对角穿越各个小方格(即,只能向上下左右四个方向移动且不能离开网格)。
输入格式
第一行是一个整数,表示正方形的宽度 N。
后面 N 行,每行 N 个不大于 100 的正整数,为网格上每个小方格的费用。
输出格式
输出一个整数,表示至少需要的费用。
数据范围
1≤N≤100
输入样例:
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
输出样例:
109
样例解释
样例中,最小值为 109=1+2+5+7+9+12+19+21+33。
代码:
#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日
边栏推荐
- Example of parameter passing from laravel query constructor to closure method
- 【概率论】条件概率、贝叶斯公式、相关系数、中心极限定理、参数估计、假设检验
- leetcode 715. Range module (hard)
- Ctrip ticket app KMM cross end kV repository mmkv kotlin | open source
- Research on the current situation of China's modified engineering plastics market and demand forecast analysis report 2022-2028
- MOS管基本原理,单片机重要知识点
- Realize microservice load balancing (ribbon)
- Quantitative elementary -- akshare obtains stock code, the simplest strategy
- 2016年四川省TI杯电子设计竞赛B题
- Black squares in word
猜你喜欢

11、 Box styles and user interface

2021 q3-q4 investigation report on the use status of kotlin multiplatform

Re recognized! Know that Chuangyu has been selected as one of the first member units of the "business security promotion plan"

"Pinduoduo and short video speed version", how can I roast!

Build Pikachu shooting range and introduction
![[graduation season · advanced technology Er] I remember the year after graduation](/img/e7/8e1dafa561217b77a3e3992977a8ec.png)
[graduation season · advanced technology Er] I remember the year after graduation

HUST network attack and defense practice | 6_ IOT device firmware security experiment | Experiment 3 freertos-mpu protection bypass

Scala-day06- pattern matching - Generic

PHP laravel+gatewayworker completes im instant messaging and file transfer (Chapter 1: basic configuration)

Omnichannel membership - tmall membership 1: opening tutorial
随机推荐
【概率论】条件概率、贝叶斯公式、相关系数、中心极限定理、参数估计、假设检验
File decryption in webgame development
The transformation of enterprise customers' digital assets needs to suit the case
What should I do from member labels to portraits?
Introduction to the strongest swarm cluster one click deployment + hydrogen bomb level container management tool
Five problems and solutions of member operation
The loss of female scientists
New routing file in laravel framework
Scala-day03- operators and loop control
Measures to support the development of cultural and creative industries in Futian District, Shenzhen
PHP generate order number
VMware virtual machine bridging mode can not access the campus network "suggestions collection"
leetcode 715. Range 模块 (hard)
2022 edition of China's cotton chemical fiber printing and dyeing Market Status Investigation and Prospect Forecast Analysis Report
Which is safer and better for great wisdom to open an account
2021 q3-q4 investigation report on the use status of kotlin multiplatform
Demand scale forecast and investment competitiveness analysis report of China's new material market 2022-2028
PHP laravel+gatewayworker completes im instant messaging and file transfer (Chapter 1: basic configuration)
SQL injection
Using the methods in the repository to solve practical problems