-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1004四维.CPP
54 lines (52 loc) · 1014 Bytes
/
1004四维.CPP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<vector>
#define IL inline
#define re register
using namespace std;
IL int read()
{
re int res=0;
re char ch=getchar();
while(ch<'0'||ch>'9')
ch=getchar();
while(ch>='0'&&ch<='9')
res=(res<<1)+(res<<3)+(ch^48),ch=getchar();
return res;
}
int n;
int f[10][10];
int dp[10][10][10][10];
int main()
{
n=read();
int tx=read(),ty=read(),tz=read();
while(tx!=0||ty!=0||tz!=0)
{
f[tx][ty]=tz;
cin>>tx;
cin>>ty;
cin>>tz;
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
for(int k=1;k<=n;k++)
for(int l=1;l<=n;l++)
{
int now=0;
now=max(now,dp[i-1][j][k][l-1]+f[i][j]+f[k][l]);
now=max(now,dp[i][j-1][k][l-1]+f[i][j]+f[k][l]);
now=max(now,dp[i-1][j][k-1][l]+f[i][j]+f[k][l]);
now=max(now,dp[i][j-1][k-1][l]+f[i][j]+f[k][l]);
if(i==k&&j==l) now-=f[i][j];
dp[i][j][k][l]=now;
}
cout<<dp[n][n][n][n];
return 0;
}