最近我对子集求和问题产生了兴趣,该问题是在超集中找到零和子集.我在SO上找到了一些解决方案,此外,我遇到了一个使用动态编程方法的特定解决方案.我根据他的定性描述在python中翻译了他的解决方案.我正在尝试对更大的列表进行优化,这会占用大量的内存.有人可以推荐优化或其他技术来解决这个特殊问题吗?这是我在python中的尝试:
import random
from time import time
from itertools import product
time0 = time()
# create a zero matrix of size a (row), b(col)
def create_zero_matrix(a,b):
return [[0]*b for x in xrange(a)]
# generate a list of size num with random integers with an upper and lower bound
def random_ints(num, lower=-1000, upper=1000):
return [random.randrange(lower,upper+1) for i in range(num)]
# split a list up into N and P where N be the sum of the negative values and P …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用以下代码在UITableViewCell中以宽度方式居中UIImageView:
// self.cover_image is a UIImage variable
// cell is a UITableCellView
UIImageView* backcover_imageview = [[[UIImageView alloc] initWithImage:self.cover_image] autorelease];
[backcover_imageview sizeToFit];
//center image
//float xPos = cell.contentView.frame.size.width - (self.cover_image.size.width/2);
//TODO: need better solution
//Eyeballing attempt:
float xPos = self.cover_image.size.width - 25;
CGRect bookcover_frame = backcover_imageview.frame;
bookcover_frame.origin.x = xPos;
backcover_imageview.frame = bookcover_frame;
backcover_imageview.tag = 9000;
backcover_imageview.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
[cell.contentView addSubview:backcover_imageview];
Run Code Online (Sandbox Code Playgroud)
我试图将UIImageView置于UITableCellView的中心,无论iPad或iPhone设备的方向如何.有谁知道正确的方法吗?
我正在使用mocha来运行纯粹在coffeescript中的测试.我还希望能够使用istanbul生成代码覆盖率报告.
注意,我--compilers coffee:coffee-script/register在mocha.opts文件中使用带有选项的mocha .
我遇到的问题是,不包括需要其他coffeescript源文件的测试.相反,我需要js文件,它被覆盖得很好.
我错过了什么吗?
我的npm test命令是:istanbul test --report html -x 'vendor/**' _mocha.我npm test --coverage用来强制执行伊斯坦布尔的覆盖效用.
这是一个mocha测试的样本(./test/test.coffee):
# Project
# require ../src/main.coffee
main = require('../src/main')
# Chai
chai = require('chai')
assert = chai.assert
should = chai.should()
expect = chai.expect
describe 'something', (done) ->
describe "when given something", ->
it "should do this", ->
# tests using chai API here
something = new main()
Run Code Online (Sandbox Code Playgroud) algorithm ×1
coffeescript ×1
ios ×1
ipad ×1
iphone ×1
istanbul ×1
mocha.js ×1
node.js ×1
python ×1
subset-sum ×1
uiimageview ×1
uitableview ×1