diff --git a/usacotools.java b/usacotools.java index 1748451..95548ad 100644 --- a/usacotools.java +++ b/usacotools.java @@ -15,6 +15,7 @@ public abstract class usacotools { public static ArrayList console=new ArrayList(); public static String error="Error"; public static int debugcode=-1; + public static boolean DEBUG=false; public static boolean isrect(int[][] map,int x,int y) { int cachedsize=-1; int cachey=-1; @@ -135,6 +136,24 @@ public static int binarySearch(int arr[], int l, int r, int x) return -1; } + public static int[][] copy2D(int[][] a){ + int[][] b=new int[a.length][]; + for(int i=0;iW) { + result=ks(W,wt,val,n-1); + + + + }else { + result=Math.max(val[n-1]+ks(W-wt[n-1],wt,val,n-1),ks(W,wt,val,n-1)); + } + dpcache[n][W]=result; + return result; + } + public static void kssetup(int n,int W) { + dpcache=new int[n+1][W+1]; + } public static void main(String[] args) throws Exception{ /* * Short demo of stuff @@ -339,26 +378,46 @@ public static void main(String[] args) throws Exception{ print("Welcome to the demo"); print(">",""); int val; + /* int[][] testarray= { - {1,1,1,1,1,1,1,1}, - {1,1,1,0,0,1,1,2}, - {0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0}, - {1,1,1,1,1,1,1,1}, - {1,1,1,1,1,1,1,1}, + {1,1,2,7,7,1,1,1}, + {1,1,4,0,7,1,2,2}, + {0,3,6,9,1,0,0,0}, + {0,3,0,1,0,0,0,0}, + {0,3,0,0,0,0,0,0}, + {1,1,5,1,3,1,1,1}, + {1,1,1,1,3,1,1,1}, }; - print("Roation of 90 degrees\n Before \n\n\n\n"); + */ + int[][] testarray= { + {1,2,3,1}, + {4,5,6,2}, + {7,8,9,3}, + {10,69,1,4} + + }; + print("Roation of 90 degrees\n Before \n "); show2Darr(testarray); print("After \n"); show2Darr(rotate90cw(testarray)); + print("BEFORE:"); + int[][] ii= { + {1,1,2,3}, + {1,0,2,1}, + {1,1,1,1}, + {1,2,3,4} + }; + show2Darr(ii); + print("After H reflect:"); + show2Darr(reverseh(ii)); + try { val=sc.nextInt(); }catch(Exception e) { print("Oops that did not go well please rerun and choose a INTEGER"); val=-1; report(e); - print("How about we test erro reporting"); + print("How about we test error reporting"); console(); } if(1==val) {