POJ 1011 Sticks(dfs+剪枝)
来源:互联网 发布:调色软件 编辑:程序博客网 时间:2024/06/02 11:49
//// main.cpp// Richard//// Created by 邵金杰 on 16/8/31.// Copyright © 2016年 邵金杰. All rights reserved.//#include<iostream>#include<cstdio>#include<vector>#include<cstring>#include<algorithm>using namespace std;vector<int> stick;const int maxn=1000+10;int vis[maxn];int n;int totlen=0,L;int nlastNo;bool dfs(int n,int m){ if(n==0&&m==0) return true; if(m==0) m=L; int nstartNo=0; if(m!=L) nstartNo=nlastNo+1; for(int i=nstartNo;i<stick.size();i++) { if(!vis[i]&&stick[i]<=m) { if(i>0&&vis[i-1]==0&&stick[i]==stick[i-1]) continue; vis[i]=1;nlastNo=i; if(dfs(n-1,m-stick[i])){ return true; } else { vis[i]=0; if(stick[i]==m||m==L) return false; } } } return false;}int main(){ int slen; while(scanf("%d",&n)&&n) { totlen=0; stick.clear(); for(int i=0;i<n;i++) { scanf("%d",&slen); totlen+=slen; stick.push_back(slen); } sort(stick.begin(),stick.end(),greater<int>()); for(L=stick[0];L<=totlen/2;L++) { if(totlen%L) continue; memset(vis,0,sizeof(vis)); if(dfs(n,L)) { cout<<L<<endl; break; } } if(L>totlen/2) cout<<totlen<<endl; } return 0;}
0 0
- poj 1011 sticks (dfs+剪枝)
- POJ - 1011 - Sticks (DFS + 剪枝)
- poj 1011 Sticks (DFS+剪枝)
- POJ 1011 Sticks (DFS + 剪枝)
- POJ 1011 Sticks(DFS + 剪枝)
- POJ 1011 Sticks(dfs+剪枝)
- poj 1011 sticks (dfs + 剪枝)
- poj 1011Sticks(DFS +剪枝)
- POJ 1011 Sticks dfs + 剪枝
- POJ 1011 Sticks DFS+剪枝
- poj 1011 Sticks -----dfs+剪枝
- POJ 1011 Sticks (DFS + 剪枝)
- POJ 1011 Sticks DFS 剪枝
- poj 1011 Sticks 【DFS】+【剪枝】
- [POJ 1011]Sticks(DFS剪枝)
- poj 1011 :Sticks (dfs+剪枝)
- POJ 1011 Sticks dfs+剪枝
- poj 1011 Sticks(dfs+剪枝)
- js控住DOM实现发布微博简单效果
- 关于Sturts1.3从页面获取日期然后录入数据库的问题
- 略解cocos2d-x 延迟动画系统。
- leetcode二叉树遍历
- 将一串字符串转变为驼峰样式(字符串练习)
- POJ 1011 Sticks(dfs+剪枝)
- [PAT] B1015
- js中常用的Tab切换
- 抽象语法树
- 从全局中通过class类名获取标签
- 简单的碰壁反弹效果
- event事件学习小节
- 简单的使用键盘控制方块移动
- 如何让word里的统计图动态更新