2012 = 2 2 * 503 Might be useful tomorrow. – MG. PotW Solution int dp(int pos, int k) { if (k > lim) return -(1 << 30); if (pos == n) return 0; int res.

Slides:



Advertisements
Similar presentations
Hoare-style program verification K. Rustan M. Leino Guest lecturer Rob DeLines CSE 503, Software Engineering University of Washington 26 Apr 2004.
Advertisements

Definition of the Derivative Using Average Rate () a a+h f(a) Slope of the line = h f(a+h) Average Rate of Change = f(a+h) – f(a) h f(a+h) – f(a) h.
W E S T V I R G I N I A 2012 School Health Profiles Report Weighted Lead Health Education Teacher Survey Results.
W E S T V I R G I N I A 2012 School Health Profiles Report Weighted Lead Physical Education Teacher Survey Results.
W E S T V I R G I N I A 2012 School Health Profiles Report Weighted Principal Survey Results.
Gunn ProCo Lynbrook 1st, 2nd, 3rd*, 4th. Results! 1st: Johnny, MG, Victor (perfect score) 2nd: Julia, Tony, Jimmy (perfect score) 3rd: Team "Lynbrook.
Algorithm Design approaches Dr. Jey Veerasamy. Petrol cost minimization problem You need to go from S to T by car, spending the minimum for petrol. 2.
For(int i = 1; i
UniData to SQL Conversion Don’t lose your Informer investment…
Copyright © 2012 Pearson Education, Inc. Chapter 14: More About Classes.
T E N N E S S E E 2012 School Health Profiles Report Weighted Lead Health Education Teacher Survey Results.
N E B R A S K A 2012 School Health Profiles Report Weighted Lead Health Education Teacher Survey Results.
Dynamic Programming (DP)
Functions Prototypes, parameter passing, return values, activation frams.
The Aftercow Replacing math with cow since PotW Solution PotW Solution (credits to Jimmy) class Edge implements Comparable { int toNode, dist; public.
Templates in C++. Generic Programming Programming/developing algorithms with the abstraction of types The uses of the abstract type define the necessary.
Divisor máximo de dois inteiros. unsigned int gcd(unsigned int A, unsigned int B) { if (B > A) return gcd(B,A); else if (B==0) return A; else return gcd(B,A%B);}
第三次小考. #include using namespace std; int aaa(int *ib,int a1,int a2) { int u,v; int m=(a1+a2)/2; if(a1==a2)return ib[a1]; u=aaa(ib,a1,m); cout
Given Connections Solution
Pointers Example Use int main() { int *x; int y; int z; y = 10; x = &y; y = 11; *x = 12; z = 15; x = &z; *x = 5; z = 8; printf(“%d %d %d\n”, *x, y, z);
Call Stacks John Keyser. Stacks A very basic data structure. – Data structure: a container for holding data in a program. – Classes, structs can be thought.
 Methods of abortion  Statistics  Possible solutions.
L IMITS OF I NFINITE S EQUENCES Ch. 13 (4). What happens to each term as n gets very large?
Boolean lessThanThree; Defaults to false.. PotW Solution - Compression int dp(int i, int cnt) { if (cnt > lim) return (1
Game theory Impartial Games.  Two-person games with perfect information  No chance moves  A win-or-lose outcome  Impartial games ◦ Set of moves available.
Happy Birthday Julia Courier New. USACO December Contest - Congratulations to Jon+Julia+Andy for promoting to gold And Johnny - 2th place in gold among.
Pythagorean Theorem Unit Review Fill out your unit review sheet and work these problems. You will go over these problems on Friday before taking your test.
1. Introduction to D.P D.P : Method of finding optimal solution as a sequence of decisions.
Agenda Excel Tutorial Agenda Finish Excel Tutorials
Do Now 1) Once the war is over, what do you think African Americans soldiers will do?2) What problems might they encounter?
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
Solving Equations Using Logs. True or False? 1.Log 4 = log Log 15 = log 3 x log 5 3.Log 4 = log 8 – log 2 4.Log 64 = 2 log 8 5.Log 64 = 8 log 2.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Sorting Arrays ANSI-C. Selection Sort Assume want to sort a table of integers, of size length, in increasing order. Sketch of algorithm: –Find position.
2009/12/8 Report 報告學生 : 黃健瑋 指導教授 : 李正帆 1. Content seq_file structure proc file Data structure(not completed) 2.
Return to Home! Go To Next Slide! Return to Home! Go To Next Slide!
Семинар-презентация. Типография ДЕАЛ – это: 12-летний опыт работы и репутация надежного партнера Высокие оценки качества нашей работы Готовность к сложным.
BIG DATA Initiative SMART SubstationBig Data Solution.
What is a compiler? Compiler Source code (e.g. C++) Target code
The Quadratic Formula..
Agenda Warmup Finish 2.4 Assignments
Quadratic Formula Solving for X Solving for quadratic equations.
Find the experimental probability that you make a free throw.
WARM UP: Graph the following inequality:
BACK SOLUTION:
تاثیر هورمون IBA و BAP بر روی ریشه های جانبی وجوانه زایی گل رز
Rounding Bingo.
What type of spacecraft is this? What might be its purpose?
Data Structures and Algorithms

C-to-LC3 Compiler Over the course of the next two weeks, you will build a program that will compile C code to LC-3 assembly language Don't panic! You.
Dynamic Memory A whole heap of fun….
How to determine whether a given set of vectors
6-1 Solving Systems by Graphing
Packet #26 The Precise Definition of a Limit
Metric System SOL 6.9.
X y y = x2 - 3x Solutions of y = x2 - 3x y x –1 5 –2 –3 6 y = x2-3x.
What type of spacecraft is this? What might be its purpose?
Trial and Improvement Cube root.
The Stack.
Main() { int fact; fact = Factorial(4); } main fact.
The Quadratic Formula..
5.1 -Systems of Linear Equations
Tomorrow May Be Too Late!
How Memory Leaks Work with Memory Diagram
The Quadratic Formula..
We have the following incomplete B&B tree:
8.5 Use Properties of Trapezoids and Kites
Graphing Systems of Equations.
Presentation transcript:

2012 = 2 2 * 503 Might be useful tomorrow. – MG

PotW Solution int dp(int pos, int k) { if (k > lim) return -(1 << 30); if (pos == n) return 0; int res = mem[pos][k]; if (res != -1) return res; res = 0; int cur = k % 2; int stay = (s[pos] == '0' + (1 - cur)); res = max(res, dp(pos + 1, k) + stay); int flip = (s[pos] == '0' + (cur)); res = max(res, dp(pos + 1, k + 1) + flip); return res; }

Gunn Programming Contest Feb. 25, 9AM – 3PM ProCo-like contest at Gunn High School o Teams of up to 3 o 2 hour round, 12 problems o A good number of the problems at APCS A level, with more advanced problems also included Will be worth PotW credit (exact credit TBA) Register at Other dates: o March 17 – Harker Programming Contest o May 19 – Stanford ProCo

February USACO! Todays the last day to take the February USACO! o Take it if you havent already! (Even though AMC is tomorrow…) 5 points PotW credit for participating (as usual)

Compression Representing data with smaller amounts of data o Note that all data is essentially binary There are various file formats for compressed files o General files: "zip", "tgz", "tar" o In fact, "jar"s are really just augmented "zip" files o Images: "jpg", "png", "gif" o Sound: "mp3", "wav", "wma" o Movies: "so many we're not even going to try to list some of them here" o Executables, 3D Models, etc. Two distinct variations: lossless and lossy

Lossless Compress the data so that the process is reversible No scheme can guarantee decrease in file size o One-to-one mapping between possible file input/output makes this impossible Instead, schemes often take advantage of repetition in data o Text files often repeat certain letters more frequently o Images might feature certain colors o Neighboring pixels are often close in color Examples: ".png", most general formats

Simple Encoding Algorithms Run-Length Encoding (RLE) o Scan left to right on the data o Group identical elements that appear consecutively o Store the first element + a count Huffman Trees o Depending on how often a certain character or word appears, assign it a binary id o More common words should be assigned more bits o However, no id can be a prefix of another

Lossy Take advantage of "unnoticeable" imperfections in data o Audio, image, and movie files depend on this technique Often use differencing techniques o E.g.: In a movie, each successive frame can be differenced from the previous one to reduce data storage Often have ability to specify quality

Images Specialized optimizations are designed to trick the human eye o ".jpg" files are notorious for their blockiness and failure to preserve sharp edges o ".gif' files omit colors and then use a dithering technique to emulate shades of color

PotW – Silly Compression As part of a new compression algorithm, Bessie is trying to modify a sequence of data of length N so that it contains at most K distinct values. However, it costs |a - b| additional bits to change an integer a into an integer b. Tell her the optimal sequence she should modify the original sequence into. If there are multiple solutions, output any. For 30 points, solve for N < 20. For 50 points, solve for N < 100. For bragging rights, solve for N < Time Limit: 2 seconds. Note: The second and third tasks are very difficult

Silly Compression (cont.) Sample Input #1: 3 2 (N K) (elements of the original sequence) Output: 1 (minimal cost is 1) (7 7 3 is another option) Sample Input #2: Output: ( is another option)

Hints Note that an optimal sequence always exists such that: o Each element of the original sequence should be shifted to its closest relative in the new sequence o Each element of the new sequence should appear in the original sequence o Thus, the first task can be solved with a exponential-time brute force Try all n choose k possibilities 20 choose 10 fits well within time limit Second task: o Note that the element of a sequence that minimizes the total distance to the other elements is the median o Use dynamic programming after sorting