diff options
| author | Yuval Adam <yuv.adm@gmail.com> | 2011-05-06 11:38:24 +0300 |
|---|---|---|
| committer | Yuval Adam <yuv.adm@gmail.com> | 2011-05-06 11:38:24 +0300 |
| commit | 0f85b7c4d318eeac2e51df78a846a9ea1d14064e (patch) | |
| tree | 3ac586244cfdc53911534aa5d9c2bb91bbc5384c | |
| parent | 3a320c5f0555a275ebc880381736879e8048acb8 (diff) | |
misc changes
| -rw-r--r-- | 2009/qual/c/1.out | 1 | ||||
| -rw-r--r-- | 2010/1a/b/b.py | 28 |
2 files changed, 19 insertions, 10 deletions
diff --git a/2009/qual/c/1.out b/2009/qual/c/1.out index 999026c..e69de29 100644 --- a/2009/qual/c/1.out +++ b/2009/qual/c/1.out @@ -1 +0,0 @@ -Case #1: 7Case #2: 2Case #3: 0
\ No newline at end of file diff --git a/2010/1a/b/b.py b/2010/1a/b/b.py index f22f706..72c1127 100644 --- a/2010/1a/b/b.py +++ b/2010/1a/b/b.py @@ -1,16 +1,26 @@ f = open('1.in', 'r') o = open('1.out', 'w') -def smooth(a, d, i, m): - if len(a) <= 1: +class memoized(object): + def __init__(self, func): + self.func = func + self.cache = {} + def __call__(self, *args): + try: + return self.cache[args] + except KeyError: + value = self.func(*args) + self.cache[args] = value + return value + except TypeError: + return self.func(*args) + +@memoized +def smooth(a, f, d, i, m): + if not a: return 0 - if abs(a[0]-a[1]) > m: - cd = d + smooth(a[1:], d, i, m) - ci = i + smooth(a[1:], d, i, m) - cc = c - return min(cd, ci, cc) + smooth(a[1:], d, i, m) - else: - return smooth(a[1:], d, i, m) + + best = smooth(a[:-1], f, d, i, m) + d T = int(f.readline().strip()) |
