FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java-DSA/DynamicProgramming.java at main · shanks-d-fury/Java-DSA · GitHub
shanks-d-fury
/
Java-DSA
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java-DSA
/
DynamicProgramming.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
30 lines (27 loc) · 995 Bytes
Breadcrumbs
Java-DSA
/
DynamicProgramming.java
Copy path
File metadata and controls
30 lines (27 loc) · 995 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
public
class
DynamicProgramming
{
public
static
void
main
(
String
args
[]) {
long
startTime
=
System
.
currentTimeMillis
();
//
// int[] val = { 15, 14, 10, 45, 30 };
// int[] wt = { 2, 5, 1, 3, 4 };
int
[]
val
=
Genarate_Random
.
IntArray
(
5
,
10
,
20
);
int
[]
wt
=
Genarate_Random
.
IntArray
(
5
,
1
,
5
);
int
W
=
7
;
System
.
out
.
println
(
kanpsack0_1
(
val
,
wt
,
W
,
val
.
length
-
1
));
//
long
endTime
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"Time taken : "
+ (
endTime
-
startTime
) +
" ms
\n
"
);
}
public
static
int
kanpsack0_1
(
int
[]
val
,
int
[]
wt
,
int
W
,
int
i
) {
if
(
i
==
0
||
W
==
0
) {
return
0
;
}
if
(
wt
[
i
] <=
W
) {
int
ans1
=
val
[
i
] +
kanpsack0_1
(
val
,
wt
,
W
-
wt
[
i
],
i
-
1
);
int
ans2
=
kanpsack0_1
(
val
,
wt
,
W
,
i
-
1
);
return
Math
.
max
(
ans1
,
ans2
);
}
else
{
return
kanpsack0_1
(
val
,
wt
,
W
,
i
-
1
);
}
}
}
Back
|
FazBrowse Home
|
New Git URL