CodeForcesGym 100735D Triangle Formation
Triangle Formation
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
2
1 1
0
3
2 2 2
1
6
2 2 3 4 5 6
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的更多相关文章
- 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 ...
- [LeetCode] Triangle 三角形
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
- [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, ...
- [LeetCode] Pascal's Triangle 杨辉三角
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- 【leetcode】Pascal's Triangle II
题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...
- 【leetcode】Pascal's Triangle
题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...
- POJ 1163 The Triangle(简单动态规划)
http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- Triangle - Delaunay Triangulator
Triangle - Delaunay Triangulator eryar@163.com Abstract. Triangle is a 2D quality mesh generator an ...
- LeetCode 118 Pascal's Triangle
Problem: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows ...
随机推荐
- C++11系列-什么是C++11
什么是C++0x? C++0x是C++最新标准标准化过程中的曾用名,在这一系列文章中我们将介绍最新标准添加的一系列新的语言特性.在2011年9月份,C++0x正式由官方发布并命名C++11,现在很多编 ...
- kubernetes Traefik ingress配置详解
理解Ingress 简单的说,ingress就是从kubernetes集群外访问集群的入口,将用户的URL请求转发到不同的service上.Ingress相当于nginx.apache等负载均衡方向代 ...
- html5做的一个激光条
<!DOCTYPE HTML><html lang="zh-cn"><head> <title>CSS3激光加载条</titl ...
- 网站防止用户复制的js方法
<script type="text/javascript">function stop() {return false;}document.oncontextmenu ...
- [App Store Connect帮助]三、管理 App 和版本(3)查找 App
在“我的 App”中,使用工具栏控件快速查找 App. 搜索 App: 在搜索栏中输入文本. 您可以输入 App 的名称.Apple ID(App 标识符).套装 ID,或 SKU.套装 ID 和 S ...
- [Swift通天遁地]七、数据与安全-(10)文件的加密压缩和解压加密压缩
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- 微信小程序之上传多张图片
之前写过一篇小程序商品发布的博客,里面有上传多张图片的功能,这里单独拿出来实现以下,小程序的upLoadFile一次只能上传一张图片,需要循环调这个接口来实现 for (var i = 0; i &l ...
- ACM_蛋糕小王子铁头娃
Problem Description: 铁头娃制作了很多蛋糕,想分给他的小伙伴们,他的小伙伴很喜欢铁头娃做的蛋糕,每个人都想分到最多蛋糕 铁头娃想到了一个头铁主意:先给小伙伴们从1到N编号,在1-N ...
- html表单——使用frameset写一个导航栏效果
主页面: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4 ...
- [转]Linux定时任务Crontab详解
转自:http://blog.chinaunix.net/uid-7552018-id-182133.html 今天做了个数据库的备份脚本,顺便系统得学习一下Linux下定时执行脚本的设置.Linux ...