This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pe31(n=200): | |
coin = (1, 2, 5, 10, 20, 50, 100, 200) | |
ncoin = len(coin) | |
cnt = [[0] * (n+1) for _ in xrange(ncoin+1)] | |
cnt[0][0] = 1 | |
for i in xrange(1, ncoin+1): | |
for j in xrange(n+1): | |
for k in xrange(j / coin[i-1] + 1): | |
cnt[i][j] += cnt[i-1][j - k*coin[i-1]] | |
return cnt[-1][-1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Sun Apr 13 17:27:11 2014 | |
@author: Administrator | |
""" | |
# 2.2.1 | |
def coinproblem(c, a): | |
coins = [1, 5, 10, 50, 100, 500] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Mon Apr 14 13:01:18 2014 | |
@author: Administrator | |
""" | |
# 2.3.1 | |
def bag01(n, w, v, W): | |
d = [[0] * (W+1) for _ in xrange(n+1)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Mon Apr 14 21:11:17 2014 | |
@author: Administrator | |
""" | |
class heap(): | |
def __init__(self, h): | |
self.len = len(h) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Tue Apr 15 12:18:41 2014 | |
@author: Administrator | |
""" | |
import numpy as np | |
def bigraph(G): | |
head, edge = G |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Thu Apr 17 12:40:57 2014 | |
@author: Administrator | |
""" | |
import numpy as np | |
import heapq | |
def SPFA(G, s): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [fval x] = gaboundconstraint(fun, lb ,ub) | |
%lb = -10*ones(1,10);ub = 10*ones(1,10); | |
%Schaffer = '-0.5+(sin(sqrt(sum(x.^2,2))).^2-0.5)./(1+0.001*sum(x.^2,2)).^2'; | |
%Schaffer在x = (0,0,…,0)处有全局极小点-1 | |
%Ackley = '-20*exp(-0.2*sqrt(sum(x.^2,2)/size(x,2))) - exp(sum(cos(2*pi*x),2)/nGenome) + exp(1) + 20'; | |
%Ackley在x = (0,0,…,0)处有全局极小点0 | |
%Griewank = '1/4000*sum(x.^2,2) - prod(cos(bsxfun(@rdivide,x,sqrt(1:nGenome))),2) + 1'; | |
%Griewank在x = (0,0,…,0)处有全局极小点0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Sat Apr 26 19:36:04 2014 | |
@author: Administrator | |
""" | |
import heapq | |
import numpy as np | |
from scipy.misc import imread | |
import matplotlib.pyplot as plt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [fval x] = gaunc(fun, lb ,ub) | |
tic | |
popSize = 200; | |
patternTol = 1e-10; | |
generation = 1000; | |
stopStall = 100; | |
nGenome = length(lb); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [fval x] = gaunc(fun, lb ,ub) | |
tic | |
popSize = 200; | |
patternTol = 1e-10; | |
generation = 1000; | |
stopStall = 100; | |
nGenome = length(lb); |
OlderNewer