当前位置:网站首页>动规(15)-最低通行费
动规(15)-最低通行费
2022-06-12 03:44:00 【H_Cisco】
描述
一个商人穿过一个 N*N 的正方形的网格,去参加一个非常重要的商务活动。他要从网格的左上角进,右下角出。每穿越中间1个小方格,都要花费1个单位时间。商人必须在(2N-1)个单位时间穿越出去。而在经过中间的每个小方格时,都需要缴纳一定的费用。这个商人期望在规定时间内用最少费用穿越出去。请问至少需要多少费用?注意:不能对角穿越各个小方格(即,只能向上下左右四个方向移动且不能离开网格)。
输入
第一行是一个整数,表示正方形的宽度N (1 <= N < 100);
后面 N 行,每行 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<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int i,j,n,s[105][105];
int main()
{
cin>>n;
memset(s,0x7f,sizeof(s));
s[0][1]=0;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
cin>>s[i][j];
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(s[i-1][j]>s[i][j-1])
s[i][j]+=s[i][j-1];
else
s[i][j]+=s[i-1][j];
cout<<s[n][n];
return 0;
}
边栏推荐
- Community Conference | the mosn community will release version 1.0 and promote the evolution of the next generation architecture
- 怎样拥有心灵的平和?获得一颗全新的心灵
- Final summary of addition, deletion, modification and query - 2.1 (single table - addition, deletion, modification and query)
- MySQL create user and authorize
- MongoDB精华总结
- What does hard work mean to you?
- [Clickhouse column] user initialization of new library role
- 2022 communication industry ultimate Exhibition Guide
- Convert py file to EXE file
- 19.tornado项目之优化数据库查询
猜你喜欢

[DFS "want" or "don't"] seek subsets; Seeking combination

成功解决:WARNING: There was an error checking the latest version of pip.

PostgreSQL basic introduction and deployment

如何修改mysql 查询出来的结果名称 结果1,结果2

oralce 处理列转行的三种方式 最后生成表格样式数据

Batch automated e-mail: Vika Vige table x Tencent Qianfan scene connector has made new moves, and business communication and event marketing only need 3 steps

Successfully solved: warning: there was an error checking the latest version of pip

分布式计算的八大谬论

central limit theorem

2020-12-06
随机推荐
(idea)the file size(2.85M) exceeds configured limit(2.56M). Code insight features are not available
Cloud native overview
Introduce the functions of the new project aleo
UI consistency design of products
The rise of another domestic mobile phone chip is close to the height reached by Huawei
Final summary of addition, deletion, modification and query
Special materials | household appliances, white electricity, kitchen electricity
C language array
Data flow diagram of Flink
19. Optimized database query of tornado project
Absolute positioning three ways to center the box
双目标定学习资料整理
$LastExitCode=0, but $?= False in PowerShell. Redirecting stderr to stdout gives NativeCommandError
Paper recommendation: relicv2, can the new self supervised learning surpass supervised learning on RESNET?
MySQL create user and authorize
AI interview bag | Netease mutual entertainment AI Lab artificial intelligence research engineers share on both sides
Successfully solved: warning: there was an error checking the latest version of pip
What does kotlin collaboration scope and coroutinescope mainscope globalscope viewmodelscope lifecyclescope represent respectively
Mongodb essence summary
golang的gin框架,各种接收参数的方式和各种绑定的区别?