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 ...
随机推荐
- Fy's dota2
Fy 觉得自己玩 cf,lol 这种高端游戏已经够厉害了,于 是他决定去玩 dota2.结果 fy 的鼠标右键坏了,所以他就等 到 2250 买了把闪烁匕首,用跳刀前进,准备去送泉水.但 是 fy 一 ...
- Spark 机器学习 ---TF-IDF
package Spark_MLlib import org.apache.spark.ml.feature.{HashingTF, IDF, Tokenizer} import org.apache ...
- java普通代码块、静态代码块、默认构造方法的执行顺序
package test; class Parent{ { System.out.println("父类普通代码块"); } static{ System.out.println( ...
- C# 单例3种写法
public class Singleton { private static Singleton _instance = null; private Singleton(){} public sta ...
- Python/Django 批量下载Excel
一.前提 项目上需求的变更总是时时发生的,应对需求的我们,也只能变更我们代码,所以.继前两篇之后,我们的批量下载诞生了 二.安装 本文使用zipstream库进行压缩,安装方式:pip install ...
- 数据库mysql原生代码基本操作
创建表: CREATE TABLE `biao` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '测试表', `createtime` ...
- DropDownList 数据源绑定和获取
前台代码: <td>账户名称:</td> <td> <asp:DropDownList ID="DropDownListAccount" ...
- Android内存管理(7)在AS中查看内存和cpu情况
Memory and CPU monitor Android Studio provides a memory and CPU monitor view so you can more easily ...
- UNIX环境高级编程--5
标准I/O库流和FILE对象: 所有I/O函数都是围绕文件描述符的.当打开一个文件时,即返回一个文件描述符,然后该文件描述符就用于后续的I/O操作.当用标准I/O库打开或者创建一个文件时,我们已 ...
- SSH Secure Shell Client连接centos6.5时中文字乱码处理
在学习Linux的过程中,最先碰到的是通过SSH终端连接时发现有乱码出现,使用这篇文章先从这里说起. 在 ssh , telnet 终端中文显示乱码解决办法#vim /etc/sysconfig/i1 ...