博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Induction and Recursion and Reduction
阅读量:6476 次
发布时间:2019-06-23

本文共 2920 字,大约阅读时间需要 9 分钟。

Where is the reduction? important as in dynamic programming, what is the dynamic function?

There are two major variations of reductions: reducing to a different problem or reducing to a shrunken version of the same.

Puzzler solution 

def cover(board,lab=1,top=0,left=0,size=None):    if size is None: size = len(board)    #size of subboard    s = size//2    #offsets for outer/inner squares of subboards    offsets = (0,-1),(size-1,0)    for dy_outer,dy_inner in offsets:        for dx_outer,dx_inner in offsets:            #if the outer corner is not set            #print ((dy_outer,dx_outer),(top+s+dy_inner,left+s+dx_inner))            if not board[top+dy_outer][left+dx_outer]:                #label the inner corner                #print {(top+s+dy_inner,left+s+dx_inner):lab}                board[top+s+dy_inner][left+s+dx_inner]=lab    #next label    lab +=1    if s>1:        for dy in [0,s]:            for dx in [0,s]:                #recursive calls, if s is at least 2:                #print(lab,top+dy,left+dx,s)                lab = cover(board,lab,top+dy,left+dx,s)    #return the next available label:    return labboard = [[0]*8 for i in range(8)]board[7][7] = -1#print(1,0,0,4)cover(board)for row in board: print((" %2i"*8) % tuple(row))

induction,recursion, and reduction.

Focusing on taking a single step toward a solution, the rest follows automatically.

Reduction means transforming one problem to another. We normally reduce an unknown problem to one we know how to solve.

Induction is used to show that a statement is true for a large class of objects. We do this by first showing it to be true for a base case(such as the number 1, the empty tree...) and then showing that it "carries over" from one object to the next( if it is true for n-1, then it's true for n).

Recursion is what happens when a function calls itself. Here we need to make sure the fuction works correctly for a base case and that it combines results from the recursive calls into a valid solution.

Both induction and recursion involve reducing a problem to a smaller subproblems and then taking one step beyond these, solving the full problem.

To use induction(or recursion), the reduction must be between instances of the same problem of different sizes.

The question is how we can carve up the board into smaller ones of the same shape. It's quadratic, so a natural staring point might be to split it into four smaller squares. The only thing standing between us and a complete solution at that point is that only one of the four board parts has the same shape as the original, with the missing corner. The other three are complete checkerboards. That's easily remedied, however. Just place a single tile so that it covers one corner from each of these three subboards, and, as if by magic, we now have four subproblems, each equivalent to the full problem!

转载于:https://www.cnblogs.com/grep/archive/2012/08/17/2643922.html

你可能感兴趣的文章
Mixin Network第一届开发者大赛作品介绍- dodice, diceos和Fox.one luckycoin
查看>>
安卓Glide(4.7.1)使用笔记 01 - 引入项目
查看>>
中金易云:为出版社找到下一本《解忧杂货店》
查看>>
Flex布局
查看>>
Material Design之 AppbarLayout 开发实践总结
查看>>
Flutter之MaterialApp使用详解
查看>>
DataBinding最全使用说明
查看>>
原生Js交互之DSBridge
查看>>
Matlab编程之——卷积神经网络CNN代码解析
查看>>
白洋淀周末游
查看>>
三篇文章了解 TiDB 技术内幕 —— 说计算
查看>>
copy strong weak assign的区别
查看>>
OpenCV 入门
查看>>
css 3D transform变换
查看>>
ele表格合并行之后的selection选中
查看>>
正则表达式分解剖析(一文悟透正则表达式)
查看>>
解决UILable标点符号居中的问题
查看>>
HTML5新特性教程
查看>>
SpringBoot 实战 (十七) | 整合 WebSocket 实现聊天室
查看>>
ImageOptim-无损图片压缩Mac版
查看>>