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. Bing Maps进阶系列五:通过DeepEarth的MiniMap控件为Bing Maps扩展迷你小地图

    Bing Maps进阶系列五:通过DeepEarth的MiniMap控件为Bing Maps扩展迷你小地图 Bing Maps Silverlight Control虽然为我们提供了简洁.方便的开发模 ...

  2. restrict关键字

    值得注意的是,一旦你决定使用restrict来修饰指针,你必须得保证它们之间不会互相重叠,编译器不会替你检查. 关键字restrict有两个读者.一个是编译器,它告诉编译器可以自由地做一些有关优化的假 ...

  3. Luogu3403跳楼机

    https://zybuluo.com/ysner/note/1099616 题面 给你三个数\(x\),\(y\),\(z\),问你能够凑出多少个[1,\(h\)]之间的数. 解析 处理出\(y\) ...

  4. 关于CSS中float的两点心得以及清除浮动的总结

    对一个元素运用float后,该元素将脱离正常文档流,这意味着: 1. 运用float后,该元素不再影响父元素的高度,如果一个元素的所有子元素都是float的话,那么该元素的高度是0,这样后面元素渲染的 ...

  5. Django 内容回顾

    模板 变量 {{ }} 标签 {% %} if elif else for empty forloop() with...as csrf_token 过滤器 default length add da ...

  6. 用Python一键搭建Http服务器的方法

    用Python一键搭建Http服务器的方法 Python3请看 python -m http.server 8000 & Python2请看 python -m SimpleHTTPServe ...

  7. 手势识别官方教程(7)识别缩放手势用ScaleGestureDetector和SimpleOnScaleGestureListener

    1.Use Touch to Perform Scaling As discussed in Detecting Common Gestures, GestureDetector helps you ...

  8. Hadoop基础(一)

    Hadoop 基础知识 大数据已经火了很长很长时间了,从最开始是个公司都说自己公司的数据量很大,我们在搞大数据.到现在大数据真的已经非常成熟并且已经在逐渐的影响我们的生产生活.你可能听过支付宝的金融大 ...

  9. Android 微信分享图片

    "; //微信 APPID private IWXAPI iwxapi; private void regToWx() { iwxapi = WXAPIFactory.createWXAPI ...

  10. 一篇文章告诉你如何使用EF CodeFirst做增删改查

    一.修改数据 其实修改涉及的内容挺多的,是相对于其他操作来说比较繁琐.也是本文的重头戏. 虽然都是基础内容,但是也是值得细细品味的. 1.最简单直接的修改数据就是从数据库里检索出数据修改相应的字段即可 ...