From 496239974ffb2e69b0db0c08c99eb29e9bcea6da Mon Sep 17 00:00:00 2001 From: Raymond <20248577+javaarchive@users.noreply.github.com> Date: Wed, 16 May 2018 19:59:32 -0700 Subject: [PATCH 1/2] Add files via upload --- usacotools.java | 59 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/usacotools.java b/usacotools.java index 1748451..91e84f7 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;i",""); int val; + /* + int[][] testarray= { + {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}, + }; + */ 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,2,3,1}, + {4,5,6,2}, + {7,8,9,3}, + {10,69,1,4} + }; - print("Roation of 90 degrees\n Before \n\n\n\n"); + 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) { From d6e6ae275863b54c1f6c57ed9da6c9962060ec73 Mon Sep 17 00:00:00 2001 From: Raymond <20248577+javaarchive@users.noreply.github.com> Date: Sun, 20 May 2018 12:46:22 -0700 Subject: [PATCH 2/2] Update usacotools.java --- usacotools.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/usacotools.java b/usacotools.java index 91e84f7..95548ad 100644 --- a/usacotools.java +++ b/usacotools.java @@ -346,6 +346,26 @@ public static void show2Darr(int[][] a) { public static void showarr(int[] a) { for(int x:a) {print(x+" ");} } + public static int[][] dpcache; + public static int ks(int W,int[] wt,int[] val,int n) { + int result; + if(dpcache[n][W]!=0) {return dpcache[n][W];} + if(n==0||W==0) { + result=0; + }else if(wt[n-1]>W) { + 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