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 ;
}

最新文章

  1. Vue.js入门
  2. python头部注释 vim添加头部注释
  3. 《UML大战需求分析》阅读笔记06
  4. backBarButtonItem 替换
  5. 2016HUAS_ACM暑假集训2J - 今年暑假不AC
  6. [原创] hadoop学习笔记:卸载和安装jdk
  7. 制作Andriod程序的数字签名需要使用JDK
  8. Qt4.8.6+mingw+Qgis2.4.0基于QGis的二次开发
  9. jsp与Action值得对应
  10. 史上最坑的证书报错解决方法:Code=3000 &quot;未找到应用程序的“aps-environment”的权利字符串&quot;
  11. SQL2012还原数据库操作在本地服务器上操作和用别的电脑远程连接到服务器进行操作的文件路径差异
  12. JavaScript 内存相关知识
  13. Head First Servlet and JSP
  14. 前端入门24-响应式布局(BootStrap)
  15. 三大家族(offset、scroll、client)
  16. Tex和LaTeX认识
  17. Java输入输出流详解
  18. PHP 如何自定义函数
  19. C++中的fstream,ifstream,oftream
  20. Node.js实战(四)之调试Node.js

热门文章

  1. Java事件处理机制- 事件监听器的四种实现方式
  2. bzoj3661
  3. SpringBoot入门之HelloWorld
  4. GoLang 编译exe添加ICO图标
  5. CSS 样式的优先级(重要,一定要理解)
  6. 315 Count of Smaller Numbers After Self 计算右侧小于当前元素的个数
  7. Unity学习-预制(四)
  8. Java 中 父类变量访问子类方法 需要使用 类型转换 (instenceof)关键字 /类型判断/
  9. HTML和CSS网页开发基础
  10. mysql_基础2