状压dp
dp[s]:用s所对应的木条最多能构成的三角形
转移时枚举选三根木条的选法
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n, len[15], dp[1 << 15];
int solve()
{
memset(dp, 0, sizeof(dp));
for(int s = 0; s < (1 << n); s++)
{
int id[15], cnt = 0;
for(int i = 0; i < n; i++)
if(s & (1 << i)) id[cnt++] = i;
if(cnt < 3) continue;
for(int i = 0; i < cnt; i++)
for(int j = i + 1; j < cnt; j++)
for(int k = j + 1; k < cnt; k++)
{
int add = 1, t1 = id[i], t2 = id[j], t3 = id[k];
if(len[t1] + len[t2] <= len[t3]) add = 0;
if(len[t1] + len[t3] <= len[t2]) add = 0;
if(len[t2] + len[t3] <= len[t1]) add = 0;
dp[s] = max(dp[s], add + dp[s ^ (1 << t1) ^ (1 << t2) ^ (1 << t3)]);
}
}
return dp[(1 << n) - 1];
}
int main()
{
scanf("%d", &n);
for(int i = 0; i < n; i++)
scanf("%d", &len[i]);
printf("%d\n", solve());
return 0;
}