summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--2009/qual/c/1.out1
-rw-r--r--2010/1a/b/b.py28
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())