题目链接:restore-ip-addresses
import java.util.ArrayList;
import java.util.List;
/**
 * 
		Given a string containing only digits, 
		restore it by returning all possible valid IP address combination...
                            
                            
                                分类:
其他好文   时间:
2015-04-04 09:14:43   
                                阅读次数:
113
                             
                         
                    
                        
                            
                            
                                题目链接:word-search
/**
 * 
		Given a 2D board and a word, find if the word exists in the grid.
		
		The word can be constructed from letters of sequentially adjacent cell,
		 where "adjacent" cells...
                            
                            
                                分类:
其他好文   时间:
2015-04-03 09:19:28   
                                阅读次数:
148
                             
                         
                    
                        
                            
                            
                                套用回溯 公式程序:
void backtrack (int t)
{
    if (t > n) {
       // 到达叶子结点,将结果输出
       output (x);
    }
    else {
       // 遍历结点t的所有子结点
       for (int i = f(n,t); i <= g(n,t); i ++ ) {...
                            
                            
                                分类:
编程语言   时间:
2015-04-01 17:43:01   
                                阅读次数:
150
                             
                         
                    
                        
                            
                            
                                回溯法 是 一种 在 穷举 中,裁剪 不满足 条件 的 分支,已达到 提高 效率的 方法。其基本原型 是 树的 先序遍历,从 树根 到 树叶的路径 是 问题的 一个 解。 
回溯法的基本框架 =  确定 解空间 + 深度优先遍历 + 裁剪函数 + 确定结果函数
其中 解空间,分为 子集树 和 排序树。
具体 概念 详解:参考 点击打开链接  和 点击打开链接
递归算法通用 模板如下:
...
                            
                            
                                分类:
其他好文   时间:
2015-04-01 15:32:10   
                                阅读次数:
269
                             
                         
                    
                        
                            
                            
                                题目链接:valid-sudoku
import java.util.Arrays;
/**
 * 
		Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.
		
		The Sudoku board could be partially filled, where empty cells ...
                            
                            
                                分类:
其他好文   时间:
2015-03-31 12:52:27   
                                阅读次数:
208
                             
                         
                    
                        
                            
                            
                                直接枚举n!个效率不高,回溯法更优#include #include #include using namespace std;const int Max = 10000;bool isp[Max];int vis[Max];int a[Max]= {1};int n;void is_prime(i...
                            
                            
                                分类:
其他好文   时间:
2015-03-22 09:06:02   
                                阅读次数:
161
                             
                         
                    
                        
                            
                            
                                转:http://blog.csdn.net/lcj_cjfykx/article/details/41691787分治算法一、基本概念 在计算机科学中,分治法是一种很重要的算法。字面上的解释是“分而治之”,就是把一个复杂的问题分成两个或更多的相同或相似的子问题,再把子问题分成更小的子问题……直到最...
                            
                            
                                分类:
编程语言   时间:
2015-03-22 01:40:13   
                                阅读次数:
299
                             
                         
                    
                        
                            
                            
                                //回溯法解决数字拆解的问题
#include<iostream>
usingnamespacestd;
constintN=6;
voidOutPut(int*a,intN)
{
for(inti=N-1;i>0;i--)
{
for(intj=0;j<a[i];j++)
cout<<i<<"";
}
cout<<endl;
}
voidSolve(int*a,intt,intsum)
{
if(sum==0)
OutPu..
                            
                            
                                分类:
其他好文   时间:
2015-03-17 14:28:09   
                                阅读次数:
107
                             
                         
                    
                        
                            
                            
                                1 #include 2 3 #define QUEEN_N (8) 4 5 int queen[QUEEN_N][QUEEN_N] = { 6 {0, 0, 0, 0, 0, 0, 0, 0}, 7 {0, 0, 0, 0, 0, 0, 0, 0}, ...
                            
                            
                                分类:
其他好文   时间:
2015-03-11 18:46:26   
                                阅读次数:
161
                             
                         
                    
                        
                            
                            
                                回溯法的再次利用,体会精妙之处。 多研究,多做题~~
#include
using namespace std;
int n,L,cnt,s[100];
int dfs(int cur) {
    if(cnt++==n) {
        int kase=0,ans=0,ens=0;
        for(int i=0;i<cur;i++){
            printf("...
                            
                            
                                分类:
其他好文   时间:
2015-03-10 19:28:53   
                                阅读次数:
137