poj 1011 Sticks (DFS)
来源:互联网 发布:win10怎么重置网络设置 编辑:程序博客网 时间:2024/06/10 16:27
思路:深搜就可以了。
代码:
#include<stdio.h>#include<string.h>#include<algorithm>#include<cstdio>#include<iostream>using namespace std;int n , length[70];int used[70];int len;int inf = 0x3f3f3f3f;int min , maxn;int t;bool flag;bool cmp(const int a, const int b){ return a > b;}void dfs(int i , int l , int tot){ if(flag) return ; //printf("i = %d , l = %d , tot = %d\n" , i , l , tot); if(l == 0){ tot -= len; if(tot == 0){ flag = true; printf("%d\n" ,len); return; } else if(tot < 0){ return; } else{ for(i = 0 ; used[i] ; ++i); used[i] = 1; dfs(i + 1 , len - length[i] , tot); used[i] = 0; } } else{ for(int j = i ; j < n ; j++){ //printf("j - 1 = %d\n" , j - 1); if(length[j] == length[j - 1] && !used[j - 1]) continue; if(!used[j] && l >= length[j]) { used[j] = 1; dfs(j , l - length[j] , tot); used[j] = 0; } } } return ;}int main(){ while(~scanf("%d" , &n) && n != 0){ maxn = -inf; t = 0; flag = false; memset(used , 0 , sizeof(used)); for(int i = 0 ; i < n ; i ++){ scanf("%d" , &length[i]); if(maxn < length[i]){ maxn = length[i]; } t += length[i]; } sort(length , length + n , cmp); for(len = length[0] ; len <= t / 2 ; ++len) { if(flag) break; if(t % len == 0){ flag = false; dfs(0 , len , t); } } if(!flag) printf("%d\n" , t); } return 0;}
- poj 1011 Sticks【dfs】
- poj 1011 Sticks (DFS)
- poj 1011Sticks dfs
- POJ 1011 Sticks DFS
- DFS POJ 1011 Sticks
- POJ 1011 Sticks【dfs】
- POJ 1011 Sticks dfs
- POJ 1011Sticks【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剪枝)
- global和$_GLOBALS的区别
- Java中for关键字的几种用法
- 埃及为何越来越不喜欢美国
- MS VC 自然对齐 声明示例
- QT 自定义调试信息的输出
- poj 1011 Sticks (DFS)
- Windows下tomcat jvm参数设定
- Cocos2d-x学习--IOS(1)
- ubuntu解压windows生成的zip文件时乱码问题
- compareTo 排序
- 滚动条问题--CSrollView
- C++中const限定符的一些用法
- [VS2005]解决“由于应用程序的配置不正确,应用程序未能启动,重新安装应用程序可能会纠正这个问题”
- wdOS系统上checkinstall工具的安装和应用示例