#include <bits/stdc++.h>
#define CLOSE ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl "\n"
typedef long long LL;
const int N = 30 * 6 + 5, M = N * N, mod = 1e9 + 7;
using namespace std;
int h[N], e[M], ne[M], idx, din[N], dp[N];
int n, m, cnt;
void add(int x, int y){
e[idx] = y, ne[idx] = h[x], h[x] = idx ++;
}
struct node{
int x, y, z;
}a[N];
int get(int x, int y, int z){
a[++ cnt] = {x, y, z};
a[++ cnt] = {y, x, z};
a[++ cnt] = {x, z, y};
a[++ cnt] = {z, x, y};
a[++ cnt] = {y, z, x};
a[++ cnt] = {z, y, x};
}
void topSort(){
queue<int> q;
for(int i = 1; i <= cnt; i ++){
if(din[i] == 0){
q.push(i);
dp[i] = a[i].z;
}
}
while(!q.empty()){
int t = q.front();
q.pop();
for(int i = h[t]; i != -1; i = ne[i]){
int j = e[i];
din[j] --;
dp[j] = max(dp[j], dp[t] + a[j].z);
if(!din[j]){
q.push(j);
}
}
}
}
int main()
{
while(cin >> n && n){
memset(h, -1, sizeof h);
memset(din, 0, sizeof din);
memset(dp, 0, sizeof dp);
idx = 0, cnt = 0;
for(int i = 1; i <= n; i ++){
int x, y, z;
cin >> x >> y >> z;
get(x, y, z);
}
for(int i = 1; i <= cnt; i ++){
for(int j = 1; j <= cnt; j ++){
if(a[i].x > a[j].x && a[i].y > a[j].y){
add(i, j);
din[j] ++;
}
}
}
topSort();
int ans = 0;
for(int i = 1; i <= cnt; i ++){
ans = max(ans, dp[i]);
}
cout << ans << endl;
}
return 0;
}
标签:cnt,idx,int,memset,din,++,聪明,大马
From: https://www.cnblogs.com/acwhr/p/18006318