CF 586B 起点到终点的最短路和次短路之和-LMLPHP
起点是右下角  终点是左上角
每次数据都是两行的点  输入n 表示有n列
接下来来的2行是 列与列之间的距离
最后一行是  行之间的距离
枚举就行
 
Sample test(s)
input
4
1 2 3
3 2 1
3 2 2 3
output
12
input
3
1 2
3 3
2 1 3
output
11
input
2
1
1
1 1
output
4
 # include <iostream>
# include <cstdio>
# include <cstring>
# include <algorithm>
# include <string>
# include <cmath>
# include <queue>
# define LL long long
using namespace std ; const int INF = 0x3f3f3f3f ; int a[][] ;
int b[] ; int main()
{
int n;
while(scanf("%d",&n) != EOF)
{
int i , j ;
int sum = ;
for (i = ; i < ; i++)
for (j = ; j < n- ; j++)
scanf("%d" , &a[i][j]) ;
for (i = ; i < n ; i++)
scanf("%d" , &b[i]) ;
int ans[] = {INF , INF , INF} ;
for (i = ; i < n- ; i++)
{
sum += a[][i] ;
}
sum += b[] ;
ans[] = sum ;
sort(ans , ans+) ;
for (i = ; i < n- ; i++)
{
sum = sum - a[][i] + a[][i] ;
sum = sum - b[i] + b[i+] ;
ans[] = sum ;
sort(ans , ans+) ;
}
printf("%d\n" , ans[] + ans[]) ; }
return ;
}
05-11 16:11