Triangle Formation

Time Limit: Unknown ms
Memory Limit: 65536KB

This problem will be judged on CodeForcesGym. Original ID: 100735D
64-bit integer IO format: %I64d      Java class name: (Any)

 

You are given N wooden sticks. Your task is to determine how many triangles can be made from the given sticks without breaking them. Each stick can be used in at most one triangle.

 

Input

The first line of each test case contains the number of sticks N. (1 ≤ N ≤ 15)

The second line of each test case contains N integers leni that are the lengths of the sticks. (1 ≤ leni ≤ 109).

 

Output

Output single integer R – the maximal number of triangles.

 

Sample Input

Input
2
1 1
Output
0
Input
3
2 2 2
Output
1
Input
6
2 2 3 4 5 6
Output
2

Source

 
解题:状压
 #include <bits/stdc++.h>
using namespace std;
const int maxn = ;
typedef long long LL;
int dp[<<maxn],n;
LL a[maxn];
int main() {
while(~scanf("%d",&n)) {
for(int i = ; i < n; ++i) scanf("%I64d",a + i);
sort(a,a+n);
memset(dp,,sizeof dp);
int ret = ;
//cout<<"n:"<<n<<endl;
for(int i = ; i < n; ++i) {
for(int j = i + ; j < n; ++j)
for(int k = j + ; k < n; ++k) {
if(a[i] + a[j] > a[k]) {
//cout<<"ok"<<endl;
for(int t = ; t < (<<n); ++t) {
if(((t>>i)&) || ((t>>j)&) || ((t>>k)&)) continue;
int tmp = (t|(<<i)|(<<j)|(<<k));
dp[tmp] = max(dp[tmp],dp[t] + );
ret = max(ret,dp[tmp]);
}
}
}
}
printf("%d\n",ret);
}
return ;
}

CodeForcesGym 100735D Triangle Formation的更多相关文章

  1. Codeforces Gym100735 D.Triangle Formation (KTU Programming Camp (Day 1) Lithuania, Birˇstonas, August 19, 2015)

    日常训练题解 D.Triangle Formation You are given N wooden sticks. Your task is to determine how many triang ...

  2. [LeetCode] Triangle 三角形

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

  3. [LeetCode] Pascal's Triangle II 杨辉三角之二

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...

  4. [LeetCode] Pascal's Triangle 杨辉三角

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...

  5. 【leetcode】Pascal's Triangle II

    题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...

  6. 【leetcode】Pascal's Triangle

    题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...

  7. POJ 1163 The Triangle(简单动态规划)

    http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  8. Triangle - Delaunay Triangulator

    Triangle - Delaunay Triangulator  eryar@163.com Abstract. Triangle is a 2D quality mesh generator an ...

  9. LeetCode 118 Pascal's Triangle

    Problem: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows  ...

随机推荐

  1. Jsp内置对象和EL隐藏(内置)对象

      JSP中的内置对象一共有九个, 由于有的不太常用, 所以总是记不住, 从Sun公司的网站上找到的PDF文档, 把这一部分放在这里, 以备随时查用:     JSP九个内置对象: Implicit ...

  2. 客户端JavaScript Ajax

    创建: 2017/10/21 完成: 2017/10/23   [TODO] 对Ajax收发各类型数据制作模板 补充跨域通信(cross origin) p457  HTTP通信  HTTP  超文本 ...

  3. TextMeshPro 图片字Sprite

      生成 需要一个资源  右键生成 调整位置  放在目录  使用 <sprite="NumDamage" index=1><sprite="NumDam ...

  4. 5.3QBXT模拟赛

    出题人:钟惠兴 题目名称 讨厌整除的小明 吸血鬼 鱼的感恩 题目类型 传统型 传统型 传统型 题目目录/可执行文件名 ming vamp fool 输入文件名 ming.in vamp.in fool ...

  5. [App Store Connect帮助]三、管理 App 和版本(3)查找 App

    在“我的 App”中,使用工具栏控件快速查找 App. 搜索 App: 在搜索栏中输入文本. 您可以输入 App 的名称.Apple ID(App 标识符).套装 ID,或 SKU.套装 ID 和 S ...

  6. 【洛谷1117_BZOJ4650】[NOI2016] 优秀的拆分(哈希_后缀数组_RMQ)

    题目: 洛谷1117 分析: 定义把我校某兔姓神犇Tzz和他的妹子拆分,为"优秀的拆分" 随便写个哈希就能有\(95\)分的好成绩-- 我的\(95\)分做法比fei较chang奇 ...

  7. day01_12/11/2016_Spring入门PPT

    s1 s2 s3 s4 s5 s6 s7 s8 IOC1 IOC2 入门编写1 入门编写2 入门编写3 入门编写4---心得

  8. UNIX环境高级编程--8. 进程控制

    进程控制进程标识:    每一个进程都有一个非负整型表示的唯一进程ID.虽然唯一,但是ID可以复用.当一个进程结束后,其进程ID会被延迟复用.    ID=0的进程通常是调度进程,常被称作交换进程(s ...

  9. 【转】linux下passwd命令设置修改用户密码

    1.passwd 简单说明: 我们已经学会如何添加用户了,所以我们还要学习设置或修改用户的密码:passwd命令的用法也很多,我们只选如下的几个参数加以说明:想了解更多,请参考man passwd或p ...

  10. java攻城狮之路--复习JDBC(利用BeanUtils、JDBC元数据编写通用的查询方法;元数据;Blob;事务;批量处理)

    1.利用BeanUtils的前提得要加入以下两个jar包: commons-beanutils-1.8.0.jar commons-logging-1.1.1.jar package com.shel ...