hdoj--4277--USACO ORZ(dfs+剪枝)
来源:互联网 发布:知乎live百度云 编辑:程序博客网 时间:2024/06/05 16:11
USACO ORZ
Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4367 Accepted Submission(s): 1446
Problem Description
Like everyone, cows enjoy variety. Their current fancy is new shapes for pastures. The old rectangular shapes are out of favor; new geometries are the favorite.
I. M. Hei, the lead cow pasture architect, is in charge of creating a triangular pasture surrounded by nice white fence rails. She is supplied with N fence segments and must arrange them into a triangular pasture. Ms. Hei must use all the rails to create three sides of non-zero length. Calculating the number of different kinds of pastures, she can build that enclosed with all fence segments.
Two pastures look different if at least one side of both pastures has different lengths, and each pasture should not be degeneration.
I. M. Hei, the lead cow pasture architect, is in charge of creating a triangular pasture surrounded by nice white fence rails. She is supplied with N fence segments and must arrange them into a triangular pasture. Ms. Hei must use all the rails to create three sides of non-zero length. Calculating the number of different kinds of pastures, she can build that enclosed with all fence segments.
Two pastures look different if at least one side of both pastures has different lengths, and each pasture should not be degeneration.
Input
The first line is an integer T(T<=15) indicating the number of test cases.
The first line of each test case contains an integer N. (1 <= N <= 15)
The next line contains N integers li indicating the length of each fence segment. (1 <= li <= 10000)
The first line of each test case contains an integer N. (1 <= N <= 15)
The next line contains N integers li indicating the length of each fence segment. (1 <= li <= 10000)
Output
For each test case, output one integer indicating the number of different pastures.
Sample Input
132 3 4
Sample Output
1题意:n支木棒,将这n支木棒全部用完可以组成多少个三角形,全部的木棒都用来组成一个三角形,暴力枚举加剪枝,三角形的一条边肯定是不能比三角形周长的一半大的,并且必须先把第一根木棒分给一个堆,要不然会超时#include<cstdio>#include<map>#include<cstring>#include<algorithm>using namespace std;int n,num[20],ans;__int64 now[5];__int64 sum;map<__int64,bool>st;bool check(){__int64 a=now[0],b=now[1],c=now[2];if(a>b) swap(a,b);if(a>c) swap(a,c);if(b>c) swap(b,c);if(a&&b&&c&&a+c>b&&a+b>c&&b+c>a){if(!st[a*150000+b]){st[a*150000+b]=true;return true;}}return false;}void dfs(int d){if(d==n){if(check())ans++;return ;}for(int i=0;i<3;i++){now[i]+=num[d];if(now[i]<=sum/2)dfs(d+1);now[i]-=num[d];}}int main(){int t;scanf("%d",&t);while(t--){st.clear();scanf("%d",&n);sum=0,ans=0;memset(num,0,sizeof(num));memset(now,0,sizeof(now));for(int i=0;i<n;i++)scanf("%d",&num[i]),sum+=num[i];now[0]=num[0];dfs(1);printf("%d\n",ans);}return 0;}
0 0
- hdoj--4277--USACO ORZ(dfs+剪枝)
- HDOJ 4277 USACO ORZ DFS+剪枝
- hdoj 4277 USACO ORZ 【DFS】
- HDOJ 4277 USACO ORZ 搜索 剪枝
- HDOJ 4277 USACO ORZ 搜索+剪枝
- HDOJ 4277 USACO ORZ(set判重+dfs)
- 【HDOJ 4277】 USACO ORZ (暴搜+剪枝+去重)
- 【DFS】hdu 4277 USACO ORZ
- HDU 4277 USACO ORZ DFS
- hdu 4277 USACO ORZ DFS
- USACO ORZ(hdu4277 深搜剪枝)
- HDOJ4277USACO ORZ【dfs+剪枝】
- hdu 4277 USACO ORZ (dfs暴搜+hash)
- HDU 4277 USACO ORZ(DFS爆搜 + set判重复)
- hdu 4277 USACO ORZ(dfs搜索+set判重)
- HDU 4277 USACO ORZ (dfs + hash)
- hdu 4277 USACO ORZ (dfs+hash)
- USACO ORZ(DFS+set去重)
- MySQL入门——数据表的修改1:往指定表中添加单列(字段)
- VMWare克隆或复制没有IP
- Javascript基础知识盲点总结——继承
- 学术写作利器——LaTeX入门笔记整理(不定期更新,附加使用心得)
- 环境——LINUX上 JDK 的安装
- hdoj--4277--USACO ORZ(dfs+剪枝)
- 文章标题
- 操作系统知识(7)--Shell(2)
- win10下sourcetree使用密钥克隆仓库时提示一直在加载的解决办法
- LeetCode Word Ladder II
- Perl 面向对象编程的两种实现和比较:
- lightoj 1248 Dice (III)(几何分布+期望)
- 如何将oracle数据1000行合并成一行
- C++向量