You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
using namespace std ;
const int N = 15 ;
int n ; // 方格的宽度和高度
int w [ N ] [ N ] ; // 每个方格里面的数字
int f [ N ] [ N ] [ N ] [ N ] ; // 四维的DP数组
int main ( ) {
cin > > n ;
// 接下来的每行有三个整数,第一个为行号数,第二个为列号数,第三个为在该行、该列上所放的数。
int a , b , c ;
// 一行 0 0 0 表示结束。
while ( cin > > a > > b > > c , a | | b | | c ) w [ a ] [ b ] = c ;
// 开始递推
for ( int x1 = 1 ; x1 < = n ; x1 + + )
for ( int y1 = 1 ; y1 < = n ; y1 + + )
for ( int x2 = 1 ; x2 < = n ; x2 + + )
for ( int y2 = 1 ; y2 < = n ; y2 + + ) {
if ( x1 + y1 = = x2 + y2 ) {
int t = f [ x1 - 1 ] [ y1 ] [ x2 - 1 ] [ y2 ] ; // 下下
t = max ( t , f [ x1 ] [ y1 - 1 ] [ x2 ] [ y2 - 1 ] ) ; // 右右
t = max ( t , f [ x1 - 1 ] [ y1 ] [ x2 ] [ y2 - 1 ] ) ; // 下右
t = max ( t , f [ x1 ] [ y1 - 1 ] [ x2 - 1 ] [ y2 ] ) ; // 右下
// 加上这个点的数值
f [ x1 ] [ y1 ] [ x2 ] [ y2 ] = t + w [ x1 ] [ y1 ] ;
// 如果这个点没有被重复走, 那么再加一次w(x2,y2)
if ( x1 ! = x2 & & y1 ! = y2 ) f [ x1 ] [ y1 ] [ x2 ] [ y2 ] + = w [ x2 ] [ y2 ] ;
}
}
printf ( " %d " , f [ n ] [ n ] [ n ] [ n ] ) ;
return 0 ;
}