Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update usacotools.java
  • Loading branch information
javaarchive authored May 20, 2018
commit d6e6ae275863b54c1f6c57ed9da6c9962060ec73
20 changes: 20 additions & 0 deletions usacotools.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down